-
-
Notifications
You must be signed in to change notification settings - Fork 809
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Describe the bug
ActionForm's on:sumbit event will not be called prior to the ActionForm's inner on_sumbit closure. (broken from 0.7)
Leptos Dependencies
The latest commit (b45f982)
To Reproduce
- Modify the
ActionFrominleptos/src/form.rs:
let on_submit = {
move |ev: SubmitEvent| {
if ev.default_prevented() {
crate::logging::log!("---1");
return;
}
ev.prevent_default();
crate::logging::log!("---2");
match ServFn::from_event(&ev) {
Ok(new_input) => {
action.dispatch(new_input);
}
Err(err) => {
crate::logging::error!(
"Error converting form field into server function \
arguments: {err:?}"
);
action.value().set(Some(Err(
ServerFnErrorErr::Serialization(err.to_string())
.into_app_error(),
)));
action.version().update(|n| *n += 1);
}
}
}
};- Modify the
WithActionFrominserver_fn_axumexample:
#[component]
pub fn WithActionForm() -> impl IntoView {
let action = ServerAction::<AddRow>::new();
let row_count =
Resource::new(move || action.version().get(), |_| get_rows());
view! {
<h3>Using <code>"<ActionForm/>"</code></h3>
<p>
<code>"<ActionForm/>"</code>
"lets you use an HTML "
<code>"<form>"</code>
"to call a server function in a way that gracefully degrades."
</p>
<ActionForm
action
on:sumbit=move |ev: SubmitEvent| {
leptos::logging::log!("+++1");
ev.prevent_default();
leptos::logging::log!("+++2");
}
>
<input
// the `name` of the input corresponds to the argument name
name="text"
placeholder="Type something here."
/>
<button>Submit</button>
</ActionForm>
<p>You submitted: {move || format!("{:?}", action.input().get())}</p>
<p>The result was: {move || format!("{:?}", action.value().get())}</p>
<Transition>
archive underaligned: need alignment 4 but have alignment 1
<p>Total rows: {row_count}</p>
</Transition>
}
}- Run the example and submit an input in
Using <ActionFrom>. - See the log in the console, you will see that only
---2is logged which is insideActionFromand the example'son:submithas been ignored.
Next Steps
[ ] I will make a PR
[ x ] I would like to make a PR, but need help getting started
[ x ] I want someone else to take the time to fix this
[ ] This is a low priority for me and is just shared for your information
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation