Form
Form container with field validation, labels, error messages, and helper text. Pairs labels and errors with inputs via ARIA relationships.
Primitive: Form + FormFieldARIA: role="form"
This is your public display name.
Email is required.
form.rs
use stratum_leptos::*;
view! {
<Form on_submit=handle_submit>
<FormField name="username">
<FormLabel>"Username"</FormLabel>
<Input placeholder="Enter username" />
<FormHelperText>"Your public name."</FormHelperText>
</FormField>
<FormField name="email" required=true>
<FormLabel>"Email"</FormLabel>
<Input placeholder="[email protected]" />
<FormError>"Email is required."</FormError>
</FormField>
<Button>"Submit"</Button>
</Form>
}Installation
stratum add formForm Props
| Prop | Type | Default | Description |
|---|---|---|---|
| on_submit | Option<Callback<()>> | None | Fires on form submission |
FormField Props
| Prop | Type | Default | Description |
|---|---|---|---|
| name | String | required | Field name identifier |
| label | Option<String> | None | Field label text |
| error | Option<String> | None | Error message (shows invalid state) |
| required | bool | false | Marks field as required |
| disabled | bool | false | Disables the field |
Accessibility
- Form renders with
role="form". - FormField generates paired IDs for
aria-labelledbyandaria-describedby(error). - When error is set,
aria-invalid="true"is applied to the input. aria-requiredset when required is true.