<form> element with enhanced validation, error handling, and submission features.
Import
Basic Usage
Key Props
onFormSubmit: Called when the form is valid and submitted. Receives form values as an object and event details. Automatically callspreventDefault()on the submit event.validationMode: Global validation mode for all fields -'onSubmit'|'onBlur'|'onChange'(default:'onSubmit')errors: External validation errors (e.g., from server). Object where keys match fieldnameprops.actionsRef: Ref to imperative actions likevalidate()
Validation Modes
On Submit (Default)
Validates all fields when the form is submitted, then re-validates on change:On Blur
Validates each field when it loses focus:On Change
Validates each field on every change:Per-field Override
Individual fields can override the form’s validation mode:Server-side Validation
Display errors returned from the server:errors prop should be an object where:
- Keys match the
nameprop onField.Root - Values are error messages (strings)
Custom Validation
Submission Handling
The form automatically:- Calls
preventDefault()on submit - Validates all fields before submission
- Focuses the first invalid field if validation fails
- Only calls
onFormSubmitif all fields are valid