Component
A form that validates its Fields before submitting, focuses the first invalid one, and shows server errors on the right field.
View component changelogpreview
- Validates every Field on submit and focuses the first invalid one
- Uses the browser's constraint validation (required, type, pattern, min, max) plus each Field's validate function
- Maps server errors to fields by name and clears each one as the user edits it
- onFormSubmit receives the values as an object, with repeated names collected into arrays
Import all parts of the component and piece them together
Renders a <form> with browser validation bubbles off. On submit it validates every Field inside; with invalid fields it shows their errors and focuses the first, otherwise it calls onSubmit and onFormSubmit.
| Prop | Type | Default |
|---|---|---|
errors | Record<string, string | string[]> | -- |
onFormSubmit | (values, event) => void | -- |
onClearErrors | (errors) => void | -- |
validationMode | 'onSubmit' | 'onBlur' | 'onChange' | 'onSubmit' |
noValidate | boolean | true |
asChild | boolean | false |
customRootClass | string | "" |
actionsRef | Ref<{ validate(name?): boolean }> | -- |
| Shortcut | Description |
|---|---|
Enter | Submits the form from a text control, which validates every field first. |
| Reference | What Rad UI follows |
|---|---|
Each invalid control gets aria-invalid and its error in aria-describedby; the error is announced with role="alert". |