Expand description
§leptos_form: Derive leptos forms from rust structs
§Documentation
- Docs
- GitHub repository
- Cargo package
- Minimum supported Rust version: 1.75.0 or later
§Features
- Automatic form parsing – focus on how your data is represented and not on how to get it in and out of html
- Easy specification of label and input classes, great for Tailwind integration
- Labels are derived from struct fields and can be given form-wide casing
- DOM layout customization through attributes
- Integration with popular crates
§Crate features
This crate offers the following features, all of which are not activated by default:
bigdecimal
: Provides impls forBigDecimal
cache-local-storage
: Provides support for writing intermediate form data to/from local storage.cache-serde_json
: Provides support for (de)serializing form state as JSON.chrono
: Provides impls forDateTime
,NaiveDate
,NaiveDateTime
num-bigint
: Provides impls forBigInt
andBigUint
uuid
: Provides impls forUuid
§Example
mod my_crate {
use leptos::*;
use leptos_form::prelude::*;
use serde::*;
#[derive(Clone, Debug, Default, Deserialize, Form, Serialize)]
#[form(
component(
action = create_my_data(my_data),
on_success = |DbMyData { id, .. }, _| view!(<div>{format!("Created {id}")}</div>),
reset_on_success,
),
label(wrap(class = "my-class", rename_all = "Title Case")),
)]
pub struct MyData {
pub my_name: String,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DbMyData {
pub id: i32,
pub name: String,
}
#[component]
pub fn MyComponent() -> impl IntoView {
view! {
<MyData
initial={MyData::default()}
top=|| view!(<input type="button" value="Submit" />)
/>
}
}
#[server]
async fn create_my_data(my_data: MyData) -> Result<DbMyData, ServerFnError> {
todo!()
}
}
Modules§
- cache
- components
- Common form components
- config
- Field configuration utilities
- prelude
Structs§
- Form
Diff - Wrapper type used for providing the initial and current value of the form’s main type.
- Form
Field Signal - A wrapper holding a signal for a current state, an initial state, and possibly an error.
- Render
Props - Props provided during render to a type implementing
FormField
.
Enums§
- Form
Error - Error returned while rendering or parsing html form.
- Label
Case - Case conversion. Used in the
Form
macro.
Traits§
- Default
Html Element - Specifies a data type’s default html element. Must be implemented if the field attribute in the
Form
macro is called without providing theel
argument. - Form
Component - Rendering behavior for a particular data type given the html it is rendered in.
- Form
Field - Provides utilities for a data type’s form field representation.
Must be implemented for a type to be used as a field in a struct which derives the
Form
macro. - MapSubmit
- Closure types which can be passed as the
map_submit
argument to theForm
macro.
Functions§
- Form
Field - Provides utilities for a data type’s form field representation.
Must be implemented for a type to be used as a field in a struct which derives the
Form
macro.
Derive Macros§
- Form
- Derives forms from structs.