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 form

Form Props

PropTypeDefaultDescription
on_submitOption<Callback<()>>NoneFires on form submission

FormField Props

PropTypeDefaultDescription
nameStringrequiredField name identifier
labelOption<String>NoneField label text
errorOption<String>NoneError message (shows invalid state)
requiredboolfalseMarks field as required
disabledboolfalseDisables the field

Accessibility

  • Form renders with role="form".
  • FormField generates paired IDs for aria-labelledby and aria-describedby (error).
  • When error is set, aria-invalid="true" is applied to the input.
  • aria-required set when required is true.

Source

Primitive: form.rs
Styled: form.rs