improvement: Added more detailed example for complex data submission through ActionForm. (#233)

This commit is contained in:
alexanderpolson
2025-08-24 14:09:24 -07:00
committed by GitHub
parent 04cd9e0d5a
commit 117488b574

View File

@@ -66,10 +66,16 @@ Note the use of `on:submit:capture` rather than `on:submit`. This adds an event
Server function arguments that are structs with nested serializable fields should make use of indexing notation of `serde_qs`.
```rust
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
struct Settings {
display_name: String,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
struct HeftyData {
first_name: String,
last_name: String,
settings: Settings,
}
#[component]
@@ -84,6 +90,11 @@ fn ComplexInput() -> impl IntoView {
name="hefty_arg[last_name]"
value="closures-everywhere"
/>
<input
type="text"
name="hefty_arg[settings][display_name]"
value="my alias"
/>
<input type="submit"/>
</ActionForm>
}
@@ -93,6 +104,7 @@ fn ComplexInput() -> impl IntoView {
async fn very_important_fn(hefty_arg: HeftyData) -> Result<(), ServerFnError> {
assert_eq!(hefty_arg.first_name.as_str(), "leptos");
assert_eq!(hefty_arg.last_name.as_str(), "closures-everywhere");
aseert_eq!(hefty_arg.settings.display_name.as_str(), "my alias");
Ok(())
}
```