DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.45k stars 826 forks source link

onsubmit is not called when form is child of router #305

Closed stevenliebregt closed 2 years ago

stevenliebregt commented 2 years ago

Problem

When using a router and a separate function (Component?) with a form in it, the onsubmit is never called.

Steps To Reproduce

Steps to reproduce the behavior:

use dioxus::prelude::*;

fn main() {
    dioxus::desktop::launch(app);
}

fn app(cx: Scope) -> Element {
    cx.render(rsx! (
        Router {
            ul {
                Link { to: "/", li { "Home" } },
            }
            Route { to: "/" Home {} },
        }
    ))
}

fn Home(cx: Scope) -> Element {
    cx.render(rsx! {
        div {
            h1 { "Form" }
            form {
                onsubmit: move |ev| println!("Submitted {:?}", ev.values),
                oninput: move |ev| println!("Input {:?}", ev.values),
                input { r#type: "text", name: "username" }
                input { r#type: "text", name: "full-name" }
                input { r#type: "password", name: "password" }
                button { "Submit the form" }
            }
        }
    })
}

Expected behavior

I expect the onsubmit to be called even if the form is in a separate function.

Screenshots

Not applicable

Environment:

Questionnaire

jkelleyrtp commented 2 years ago

Hmmm, I'm testing this code locally and it's the presence of the tag (the link) that's interrupting the onsubmit. If I remove the Link component the form submits properly. Does it have something to do with how HTML forms work? I know buttons in forms take on the submit role by default by some configurations can prevent that default from kicking in.

Edit:

seems to be an issue on the Dioxus side of things

Screen Shot 2022-03-11 at 2 55 24 PM

it might be the tag interrupting the parsing of the forms field.

EDIT:

Digging into this a bit more, there's actually an issue with how Dioxus chooses to pass events into the virtualdom.

jkelleyrtp commented 2 years ago

@stevenliebregt Can you see if #310 fixes this setup for you? Took a little while to figure it out and I'm sure there are more edge cases to catch.

stevenliebregt commented 2 years ago

Yeah that one fixes it