mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 06:30:20 +00:00
fix: filtering for buttons
This commit is contained in:
parent
71c96a8053
commit
2d2de36eed
2 changed files with 22 additions and 12 deletions
|
@ -11,15 +11,17 @@ fn main() {
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
Router {
|
||||||
h1 { "Form" }
|
div {
|
||||||
form {
|
h1 { "Form" }
|
||||||
onsubmit: move |ev| println!("Submitted {:?}", ev.values),
|
form {
|
||||||
oninput: move |ev| println!("Input {:?}", ev.values),
|
onsubmit: move |ev| println!("Submitted {:?}", ev.values),
|
||||||
input { r#type: "text", name: "username" }
|
oninput: move |ev| println!("Input {:?}", ev.values),
|
||||||
input { r#type: "text", name: "full-name" }
|
input { r#type: "text", name: "username" }
|
||||||
input { r#type: "password", name: "password" }
|
input { r#type: "text", name: "full-name" }
|
||||||
button { "Submit the form" }
|
input { r#type: "password", name: "password" }
|
||||||
|
button { r#type: "submit", value: "Submit", "Submit the form" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -77,7 +77,7 @@ export class Interpreter {
|
||||||
const element = this.nodes[root];
|
const element = this.nodes[root];
|
||||||
element.setAttribute("data-dioxus-id", `${root}`);
|
element.setAttribute("data-dioxus-id", `${root}`);
|
||||||
if (this.listeners[event_name] === undefined) {
|
if (this.listeners[event_name] === undefined) {
|
||||||
this.listeners[event_name] = 0;
|
this.listeners[event_name] = 1;
|
||||||
this.handlers[event_name] = handler;
|
this.handlers[event_name] = handler;
|
||||||
this.root.addEventListener(event_name, handler);
|
this.root.addEventListener(event_name, handler);
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,9 +190,13 @@ export class Interpreter {
|
||||||
this.RemoveEventListener(edit.root, edit.event_name);
|
this.RemoveEventListener(edit.root, edit.event_name);
|
||||||
break;
|
break;
|
||||||
case "NewEventListener":
|
case "NewEventListener":
|
||||||
|
console.log(this.listeners);
|
||||||
|
|
||||||
// this handler is only provided on desktop implementations since this
|
// this handler is only provided on desktop implementations since this
|
||||||
// method is not used by the web implementation
|
// method is not used by the web implementation
|
||||||
let handler = (event) => {
|
let handler = (event) => {
|
||||||
|
console.log(event);
|
||||||
|
|
||||||
let target = event.target;
|
let target = event.target;
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
let realId = target.getAttribute(`data-dioxus-id`);
|
let realId = target.getAttribute(`data-dioxus-id`);
|
||||||
|
@ -215,7 +219,7 @@ export class Interpreter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// also prevent buttons from submitting
|
// also prevent buttons from submitting
|
||||||
if (target.tagName === "BUTTON") {
|
if (target.tagName === "BUTTON" && event.type == "submit") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,11 +243,15 @@ export class Interpreter {
|
||||||
if (shouldPreventDefault === `on${event.type}`) {
|
if (shouldPreventDefault === `on${event.type}`) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type === "submit") {
|
if (event.type === "submit") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.tagName === "FORM") {
|
if (
|
||||||
|
target.tagName === "FORM" &&
|
||||||
|
(event.type === "submit" || event.type === "input")
|
||||||
|
) {
|
||||||
for (let x = 0; x < target.elements.length; x++) {
|
for (let x = 0; x < target.elements.length; x++) {
|
||||||
let element = target.elements[x];
|
let element = target.elements[x];
|
||||||
let name = element.getAttribute("name");
|
let name = element.getAttribute("name");
|
||||||
|
|
Loading…
Reference in a new issue