Capítulo 27 de 29
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).
FormOptions — key properties| Property | Purpose |
|---|---|
defaultValues | Initial values; also the type-inference source for the whole form |
onSubmit / onSubmitInvalid | Success/failure submit handlers (ch017, ch019) |
onSubmitMeta | Default submission metadata shape (ch017) |
validators | Form-level validator functions (ch008) |
validationLogic | e.g. revalidateLogic(...) for dynamic validation (ch009) |
asyncDebounceMs / asyncAlways | Async-validator timing controls |
canSubmitWhenInvalid | Allows submission despite validation errors, when explicitly needed |
listeners | Form-level side-effect listeners (ch015) |
transform | Data transformation hook |
formId | Identifier used by devtools (ch024) |
FieldOptions — key properties| Property | Purpose |
|---|---|
name | Deep-key field identifier, type-checked against the parent data shape |
defaultValue | Field-specific default (falls back to the form's defaultValues entry) |
validators | Field-level validators (ch008) |
asyncDebounceMs / asyncAlways | Same async controls, scoped to this field |
listeners | Field-level listeners (ch015) |
disableErrorFlat | Preserve nested error structure instead of flattening it |
FieldValidators / FormValidators — timing properties| Property pattern | Meaning |
|---|---|
onMount | Runs 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 / onSubmitAsync | Submit-time validation |
onDynamic / onDynamicAsync (+ onDynamicAsyncDebounceMs) | Dynamic mode validation (ch009) |
| Helper | Purpose |
|---|---|
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 |
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.onChangeListenTo/onBlurListenTo live on FieldValidators, not FormValidators — cross-field listening (ch013) is inherently a field-level concept.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.mergeForm in its main real-world use case.