From d1aea4886e10dc5e5b323769f1904cd43f78e4ca Mon Sep 17 00:00:00 2001 From: xeovalyte Date: Tue, 18 Jun 2024 13:34:20 +0200 Subject: [PATCH] Added autofocus and clear name on sumbit --- application/src/pages/add_participant.rs | 39 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/application/src/pages/add_participant.rs b/application/src/pages/add_participant.rs index c59af0b..c5ba5e5 100644 --- a/application/src/pages/add_participant.rs +++ b/application/src/pages/add_participant.rs @@ -49,15 +49,44 @@ async fn add_participant(name: String, group: String) -> Result<(), ServerFnErro /// Renders the home page of your application. #[component] pub fn AddParticipant() -> impl IntoView { - let form_submit = create_server_action::(); + let name = create_rw_signal("".to_string()); + let group = create_rw_signal("A1".to_string()); + + let name_input_ref: NodeRef = create_node_ref(); + + let form_submit_action = create_action(|input: &(String, String)| { + let input = input.to_owned(); + + async move { add_participant(input.0, input.1).await } + }); + + let form_submit = move |ev: ev::SubmitEvent| { + ev.prevent_default(); + + form_submit_action.dispatch((name.get(), group.get())); + + name.set("".to_string()); + let _ = name_input_ref.get().unwrap().focus(); + }; view! {

"Deelnemer toevoegen"

- +
- + - @@ -94,6 +123,6 @@ pub fn AddParticipant() -> impl IntoView { - +
} }