mirror of
https://github.com/leptos-rs/book.git
synced 2025-12-27 07:35:38 -05:00
improvement: Added more detailed example for complex data submission through ActionForm. (#233)
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user