-
Hi, I'm trying to implement a form which triggers a POST request once submitted (without server actions/functions). Example code below (using v0.2.0-alpha) #[component]
pub fn RenameUserForm(cx: Scope) -> impl IntoView {
let rename_action = create_action(cx,
// |Closure here with user_id and new_name|
,{
rename_user(user_id: user_id.clone(), new_name: new_name.clone())
});
view! { cx,
<ActionForm action=rename_action>
<input name="user_id"
type="text"
hidden="true"
value="test" //Hardcoded for this example
/>
<input name="new_name"
type="text"
/>
</ActionForm>
}
}
async fn rename_user(user_id: String, new_name: String) -> Result<(),()> {
// Make a POST request using reqwasm here
} I'm not quite sure how to pass the user_id and new_name values from the form into the action - how should that be done? Thanks in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yeah so Here are a few options, if you don't want to use a server function
For 4 and 5 see here. |
Beta Was this translation helpful? Give feedback.
Yeah so
<ActionForm/>
is pretty tightly coupled to server functions, as I think the docs mention but maybe not strongly enough. Maybe it should be named<ServerActionForm/>
in reality.Here are a few options, if you don't want to use a server function
<Form/>
and copy relevant parts of the<ActionForm/>
implementation<Form method="post" action="..."/>
<form method="post" action="..."/>
and let the browser handle posting correctly for younode_ref
on each of the inputs to get their values, and dispatch your action on form submitFor 4 and 5 see here.