Forms and validation
The form components work with the libraries you already use. In React, pair them with React Hook Form. In Vue, with VeeValidate. Zod holds the rules in both. Every example on this page runs as a test against the published packages.
How it fits#
- Fields with a native input inside (Input, TextArea, Checkbox) take a
refand the usual input attributes, so React Hook Form'sregister()works on them as they are. - Custom widgets (DropdownField, DatePicker, OtpInput, Switch) are bound through
Controllerin React andv-modelin Vue. - Fields show their own error. Pass the error state and the message, and the component marks the input invalid and links the message for screen readers. You don't wire any ARIA yourself.
A complete form#
A sign-up form with an email, a role picked from a dropdown and a terms checkbox. Submitting it empty shows all three errors. Filling it in submits the values.
required to drop the “(Optional)” note after its label. Keep noValidate on the form, so your schema decides what is valid, not the browser.The test that proves it is in the testing guide.
Showing errors#
Pass the field's state and its message. The component sets aria-invalid on the input, points aria-describedby at the message, and announces the message when it appears. Most fields use state and errorText; the few that differ are in the table below.
Input also takes state="success" with successText, and helperText for a hint shown while there is no error.
What each field binds to#
register()v-modelstate, errorTextregister()v-modelstate, messageregister()v-model:checkedinvalidregister()v-model:checkederrorTextController: value, onValueChangev-modelstate, errorTextController: value, onValueChangev-modelerror, errorMessageController: value, onValueChangev-model (or v-model:range)Controller: value, onValueChangev-modelController: checked, onCheckedChangev-model:checkedController: value, onValueChangev-modelFor a field bound through Controller, also pass field.onBlur as onBlur. It fires once when focus leaves the whole field, not when it moves into the field's own popover, so touched state stays right.
Without a form library#
Give each field a name and it submits with a plain <form>, custom widgets included: a dropdown submits its value through a hidden input.
Accessibility#
- Every field has a visible label. Use
label, not a placeholder, to name a field. - Errors are text, not colour alone: the message sits under the field and is read with it.
- Validate on submit first. Validating on every keystroke tells people they are wrong before they finish.
- After a failed submit, move focus to the first field with an error. React Hook Form does this by default.
