Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour for buttons with formmethod="dialog" rendered on the client #2523

Closed
MikeOnTea opened this issue Apr 13, 2024 · 1 comment

Comments

@MikeOnTea
Copy link

MikeOnTea commented Apr 13, 2024

A <button formmethod="dialog" /> within an ActionForm within a dialog submits the form and does not close the dialog when rendered on the client (as a dynamic island). It works fine when rendered on the server (closing the dialog and not submitting the form).

Tested with Leptos 0.6.10.

@gbj
Copy link
Collaborator

gbj commented Apr 15, 2024

Thanks. I like this issue because it is small, easy to fix, and allows us really easily to support a very nice part of the platform (<dialog>) better.

Repro for posterity:

use leptos::{*, html::Dialog};
use leptos_router::*;

#[server]
pub async fn server_thing() -> Result<(), ServerFnError> {
    println!("running on server");
    Ok(())
}

#[component]
pub fn App() -> impl IntoView {
    let action = create_server_action::<ServerThing>();
    let dialog_ref = create_node_ref::<Dialog>();
    create_effect(move |_| if let Some(dialog) = dialog_ref.get() {
        dialog.set_open(true);
    });
    view! {
        <dialog node_ref=dialog_ref>
            <ActionForm action>
                <button type="submit">"Call server fn"</button>
                <button formmethod="dialog">"Close dialog"</button>
            </ActionForm>
        </dialog>
    }
}

@gbj gbj closed this as completed in fe06c6b Apr 15, 2024
gbj added a commit that referenced this issue Apr 15, 2024
fix: do not submit `<ActionForm>` on `formmethod="dialog"` submission (closes #2523)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants