Skip to content
Eskais UI

Forms

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

Between 3 and 32 characters.

Try one ending in @taken.dev.

Installation

npx shadcn@latest add @eskais/form
npm packagesreact-hook-form@7.91.0@hookform/resolvers@7.0.2@standard-schema/spec@1.1.0lucide-react

Usage

Import
import {  Form,  createForm,  FieldSet,  FormActions,  FormRootError,  FormField,  formControlAdapters,  useFormField,  useFormFieldArray,  useFormInstance,  useFormWatch,  FormServerError,  createFormMessages,  formIssueMessage,  formMessagesEn,  formMessagesEs,  resolveFormMessage,  toFormErrors,} from "@/components/ui/form"import { Form, focusTarget } from "@/components/ui/form-root"import { FormActions, FormRootError } from "@/components/ui/form-actions"import {  FormContext,  clearSecrets,  errorAt,  errorText,  forgetSecrets,  issueResolver,  loadSecrets,  requiredProbe,  toFieldError,  useFormContext,} from "@/components/ui/form-context"import { FormField, formControlAdapters, useFormField } from "@/components/ui/form-field"import { useFormFieldArray, useFormInstance, useFormWatch } from "@/components/ui/form-instance"import {  FormServerError,  createFormMessages,  formIssueMessage,  formMessagesEn,  formMessagesEs,  issueFromInput,  issueFromSchema,  issuePath,  resolveFormMessage,  toFormErrors,} from "@/components/ui/form-messages"import { formRoot } from "@/components/ui/form-primitive"import {  useFieldRegistration,  useSensitiveField,  useFocusRequest,  useFormFlag,  useReportChange,  useRestoreFocusAfterPending,} from "@/components/ui/use-form-sync"

Use Form for anything with validation; FormField binds Input, Select, Checkbox and friends by name.

API reference

Form

PropTypeDefault
schemarequiredSchema–
defaultValuesDefaultValues<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.booleantrue
labelThe form's accessible name. Without it (or `aria-labelledby`), agents use its fields and buttons only.string–
aria-labelledbystring–
onPendingChange(pending: boolean) => void–
onDirtyChange(dirty: boolean) => void–
idstring–
classNamestring–
childrenReactNode–

FormRootError

PropTypeDefault
titleReactNode–
classNamestring–

FormActions

PropTypeDefault
tone"default" | "destructive""default"
confirmstring–
submitLabelrequiredReactNode–
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.booleanfalse
submitDisabledDisables only submit, for example until a required upload finishes; the form doesn't submit.booleanfalse
pendingShows the pending look for work the app runs itself (the form's own submit needs nothing); the form doesn't submit.booleanfalse
classNamestring–

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 FormRootOptions

Accessibility

  • 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.