Capítulo 26 de 29

Chapter 26: Field & Form API Classes

Core Idea

FormApi and FieldApi (from the framework-agnostic @tanstack/form-core) are the classes every framework adapter's useForm/useField wraps — this is the full method surface once you're past the render-prop layer.

Reference Tables

FormApi — key properties

PropertyPurpose
stateCurrent form state (values, errors, validation status)
storeThe reactive store underlying useSelector/Subscribe (ch014)
optionsThe FormOptions passed at construction (ch027)
fieldInfoPer-field metadata tracking, keyed by field name

FormApi — key methods

MethodPurpose
handleSubmit(submitMeta?)Validates, then calls onSubmit/onSubmitInvalid (ch017)
setFieldValue(field, updater, opts?)Sets a field's value, optionally marking it touched
getFieldValue(field)Reads a field's current value
getFieldMeta(field) / setFieldMeta(field, updater)Read/write a field's metadata
reset(values?, opts?) / resetField(field)Reset the whole form or one field to defaults
validateField(field, cause) / validateAllFields(cause)Manually trigger validation
pushFieldValue / removeFieldValue / insertFieldValue / replaceFieldValue / swapFieldValues / moveFieldValuesArray-field mutations (ch011), callable from the form level via a field name
getAllErrors()Combined form-level + field-level errors
parseValuesWithSchema()Validate against a Standard Schema without storing errors as side effects

FieldApi — key properties/methods

MemberPurpose
formBack-reference to the owning FormApi
stateThis field's current value/meta (mirrors field.state seen in every earlier chapter)
setValue(updater, opts?)Update value, triggering change validation
pushValue / removeValue / replaceValue / insertValue / swapValues / moveValue / clearValuesArray mutation methods (ch011) — the field-level counterparts of FormApi's array methods above
validate(cause, opts?)Trigger this field's validation directly
parseValueWithSchema() / parseValueWithSchemaAsync()Standard Schema validation for just this field
mount()Registers the field with the form; returns an unmount function
handleChange(updater) / handleBlur()The two event handlers every earlier chapter's examples call

Key Takeaways

  1. Every array-mutation method exists at both the FormApi level (by field name string) and the FieldApi level (on the field instance itself, ch011) — pick whichever you already have in scope.
  2. getFieldValue/setFieldValue on FormApi are the mechanism behind cross-field reads in ch013's linked-fields pattern.
  3. parseValuesWithSchema/parseValueWithSchema(Async) let you validate against a Standard Schema without it becoming a registered validator with side effects — useful for one-off checks distinct from the field's normal validation pipeline (ch008).

Connects To

  • Ch011 Arrays: the array-mutation methods listed here in full.
  • Ch027 Options & Validators Types: the option objects these classes are constructed from.
  • Ch025 React API Reference: how useForm/useField extend these same classes.