Wit Form
Validation

Schema Rules

Validate the whole form with one Zod schema. Errors appear on the matching fields, including fields inside field array rows, and rules across fields become form errors.

Travelers
$

What this shows

  • useForm({ schema }) takes any Standard Schema: Zod, Valibot, ArkType, Effect Schema, or Yup 1.7 and newer. There's no adapter to install. See Schema validation.
  • Each issue goes to the field at its path. travelers[1].age lands on the age field of the second traveler row, and contact.email on the email field.
  • An issue for the list itself ("Add at least one traveler") becomes the field array's error. Remove every traveler to see it.
  • The .refine rule has no path, so it becomes a form error. The form shows it from formState.formErrors.
  • The schema runs again as values change, so errors clear as soon as you fix them. As with any error, a field shows its error once it's touched.

The TextField and NumberField components come from the shared example components.

On this page