Form
Forms on react-hook-form with a Standard Schema (Zod, Valibot, Effect): FormField binds one registry control by name, pending submit, server errors mapped to fields, a live root error, focus on the first invalid field, and messages in any language or i18n library.
Example
form-demo.tsxCopy code
Installation
Copy code
npm packages
react-hook-form@7.91.0@hookform/resolvers@7.0.2@standard-schema/spec@1.1.0lucide-reactUsage
ImportCopy code
Use Form for anything with validation; FormField binds Input, Select, Checkbox and friends by name.
API reference
Form
| Prop | Type | Default |
|---|---|---|
schemarequired | Schema | – |
defaultValues | DefaultValues<StandardSchemaV1.InferInput<Schema> & FieldValues> | – |
onSubmitrequiredRuns with the parsed values once they pass the schema. A returned Promise keeps the form pending. A thrown `FormServerError`, `{ fieldErrors, message }` or issue list maps to the fields and the root error; any other error shows its message in `FormRootError`. | ( values: StandardSchemaV1.InferOutput<Schema>, helpers: FormSubmitHelpers<StandardSchemaV1.InferInput<Schema> & FieldValues>, ) => unknown | – |
messagesA dictionary (`formMessagesEs`) or a function of the issue, for any i18n library; English by default. | FormMessages | – |
requiredLabelWords screen readers hear after a required field's label, like "required", in the page's language. Unset, the marker is only visual and the control's own `required` state is announced; set, the words join the field's name. | string | – |
labelPlacementWhere each FormField's label sits by default: `top`, or `in`/`on` for its text controls (see Field). | FieldLabelPlacement | – |
disableWhilePendingFields are disabled while `onSubmit` runs; `false` keeps them editable. | boolean | true |
labelThe form's accessible name. Without it (or `aria-labelledby`), agents use its fields and buttons only. | string | – |
aria-labelledby | string | – |
onPendingChange | (pending: boolean) => void | – |
onDirtyChange | (dirty: boolean) => void | – |
id | string | – |
className | string | – |
children | ReactNode | – |
FormRootError
| Prop | Type | Default |
|---|---|---|
title | ReactNode | – |
className | string | – |
FormActions
| Prop | Type | Default |
|---|---|---|
tone | "default" | "destructive" | "default" |
confirm | string | – |
submitLabelrequired | ReactNode | – |
pendingLabelWhat screen readers hear once the submit has been pending for a second, in the page's language. | string | – |
cancelThe cancel button's text; shown when set. | ReactNode | – |
onCancel | () => void | – |
secondaryActionAnother control, like a "Save draft" Button, placed before cancel. | ReactNode | – |
disabledDisables submit and cancel while something outside the form is busy; the form doesn't submit. | boolean | false |
submitDisabledDisables only submit, for example until a required upload finishes; the form doesn't submit. | boolean | false |
pendingShows the pending look for work the app runs itself (the form's own submit needs nothing); the form doesn't submit. | boolean | false |
className | string | – |
FormField
Takes FormFieldProps<Values>.
Other exports
createFormFieldSetformControlAdaptersuseFormFielduseFormFieldArrayuseFormInstanceuseFormWatchFormServerErrorcreateFormMessagesformIssueMessageformMessagesEnformMessagesEsresolveFormMessagetoFormErrorsfocusTargetFormContextclearSecretserrorAterrorTextforgetSecretsissueResolverloadSecretsrequiredProbetoFieldErroruseFormContextissueFromInputissueFromSchemaissuePathformRootuseFieldRegistrationuseSensitiveFielduseFocusRequestuseFormFlaguseReportChangeuseRestoreFocusAfterPendingtype FormPropstype FormValuesOftype TypedFormtype FormSubmitHelperstype FieldSetPropstype FormActionsPropstype FormRootErrorPropstype FormControlAdaptertype FormFieldPropstype FormFieldStatetype UseFormFieldArrayOptionstype FormErrorInputtype FormErrorstype FormIssuetype FormIssueCodetype FormMessagetype FormMessageDictionarytype FormMessagestype ErrorLiketype FormContextValuetype IssueErrortype SubmitInterceptortype FieldArraytype FormRootOptionsAccessibility
- Each FormField wires label, description and error to its control with aria-describedby and aria-invalid.
- On a failed submit, focus moves to the first invalid field, or to the root error.
- Fields are disabled while submitting (configurable), and a second submit is ignored.
- A sensitive field's value never reaches a DOM attribute; it's read on submit and emptied after a successful one.
Agent actions
With a label, the form exposes submit and reset. Agents fill each field through its own part.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.