Capítulo 27 de 29

Chapter 27: Options & Validators Types

Core Idea

FormOptions/FieldOptions (plus their *Validators counterparts) are the typed shapes behind every useForm/form.Field call seen so far; formOptions() and mergeForm() are two standalone helpers for, respectively, sharing a typed options object and merging server-provided state into a client form (ch022).

Reference Tables

FormOptions — key properties

PropertyPurpose
defaultValuesInitial values; also the type-inference source for the whole form
onSubmit / onSubmitInvalidSuccess/failure submit handlers (ch017, ch019)
onSubmitMetaDefault submission metadata shape (ch017)
validatorsForm-level validator functions (ch008)
validationLogice.g. revalidateLogic(...) for dynamic validation (ch009)
asyncDebounceMs / asyncAlwaysAsync-validator timing controls
canSubmitWhenInvalidAllows submission despite validation errors, when explicitly needed
listenersForm-level side-effect listeners (ch015)
transformData transformation hook
formIdIdentifier used by devtools (ch024)

FieldOptions — key properties

PropertyPurpose
nameDeep-key field identifier, type-checked against the parent data shape
defaultValueField-specific default (falls back to the form's defaultValues entry)
validatorsField-level validators (ch008)
asyncDebounceMs / asyncAlwaysSame async controls, scoped to this field
listenersField-level listeners (ch015)
disableErrorFlatPreserve nested error structure instead of flattening it

FieldValidators / FormValidators — timing properties

Property patternMeaning
onMountRuns once when the field/form mounts
onChange / onChangeAsync (+ onChangeAsyncDebounceMs, onChangeListenTo)Change-time validation (ch008, ch013)
onBlur / onBlurAsync (+ onBlurAsyncDebounceMs, onBlurListenTo)Blur-time validation (ch008, ch013)
onSubmit / onSubmitAsyncSubmit-time validation
onDynamic / onDynamicAsync (+ onDynamicAsyncDebounceMs)Dynamic mode validation (ch009)

Standalone helpers

HelperPurpose
formOptions(opts)Returns a typed, reusable options object — useful for sharing config between formOptions-created presets and a later useForm call, or between server and client setup (ch022)
mergeForm(baseForm, serverState)Overlays server-provided partial state onto a client form instance without discarding the client form's validator configuration — the core of the SSR pattern in ch022

Key Takeaways

  1. FieldApiOptions (a related interface not repeated in full here) differs from FieldOptions mainly by requiring a form back-reference — it's what FieldApi is actually constructed from internally; application code almost always writes FieldOptions-shaped props via form.Field, not FieldApiOptions directly.
  2. onChangeListenTo/onBlurListenTo live on FieldValidators, not FormValidators — cross-field listening (ch013) is inherently a field-level concept.
  3. mergeForm is the one helper here worth remembering by name outside SSR contexts too — anywhere client state needs to be reconciled with an externally-computed partial state, not just the Next.js/Remix/Start cases in ch022.

Connects To

  • Ch008 Form Validation, ch009 Dynamic Validation, ch013 Linked Fields, ch015 Listeners: the guides these option properties configure.
  • Ch022 SSR & Meta-Frameworks: mergeForm in its main real-world use case.
  • Ch026 Field & Form API Classes: the runtime classes these options construct.