Forms
Build a validated form with Hextech UI, React Hook Form and Zod.
Use the canonical Field, Input and Button components. React Hook Form owns the form values, and Zod validates the data before submission.
Install
Complete Installation, then add the controls:
npx shadcn@latest add https://hextech-ui.vercel.app/r/field.jsonnpx shadcn@latest add https://hextech-ui.vercel.app/r/button.jsonnpx shadcn@latest add https://hextech-ui.vercel.app/r/alert.jsonThe Field registry item also installs Input. Add the form dependencies separately:
npm install react-hook-form @hookform/resolvers zodProfile form
Submit an empty name to see client validation. Enter taken to simulate a server validation error. Enter another name to complete the local submission, or reset the form. No account or backend is connected.
Profile form
Values and validation
Controller supplies the Input value, change handler, blur handler and focus ref. Keep a default value for every controlled field. Avoid registering the same input with both Controller and register.
Pass the external error state to Field with invalid, and render the message through FieldError. FieldLabel and FieldDescription remain associated with the input. The canonical Field keeps an 8px label-to-control gap in both themes.
Submission and server errors
Replace the local delay with your own request. Validate the data again on the server. Use setError to show a returned field error and shouldFocus to focus its input. Catch network failures and show a clear form-level message; retain the user's values so they can retry.
The submit Button uses loading={form.formState.isSubmitting} to prevent repeated activation and announce pending work. Keep other destructive or reset actions disabled while submitting. Show success only after the request succeeds.
Reset
form.reset() restores the declared defaults and clears form errors and dirty state. Reset any separate success message at the same time. When loading another record, supply its values to reset(record) instead of switching between controlled and uncontrolled input state.
Group related controls
Use Fieldset for a shared legend, FieldGroup for layout, and Checkbox Group for shared selection. Input Group adds text or buttons to an input; Button Group groups actions without introducing toolbar arrow-key behavior.
This form combines them with the same validation and submission ownership. Clearing the name or all roles shows field errors. Reset restores the defaults.
npx shadcn@latest add https://hextech-ui.vercel.app/r/fieldset.jsonnpx shadcn@latest add https://hextech-ui.vercel.app/r/checkbox-group.jsonnpx shadcn@latest add https://hextech-ui.vercel.app/r/input-group.jsonnpx shadcn@latest add https://hextech-ui.vercel.app/r/button-group.jsonComposed party settings
See the official React Hook Form documentation, Zod guide and Base UI forms handbook for the underlying contracts.