Form Instance
A Form Instance represents an individual form and provides methods for managing form state. Create one using theinjectForm function with Angular’s dependency injection:
Field
A Field represents a single form input element. Create fields using thetanstackField directive with a template reference variable:
name prop must match a key in your form’s default values. The template variable exposes the field’s API through the api property.
Field State
Each field maintains its own state including current value, validation status, and metadata. Access it viafieldApi.state:
Field Metadata Flags
Four key states track user interaction:- isTouched - Set after the user changes or blurs the field
- isDirty - Set after the field value changes (persistent, even if reverted)
- isPristine - Remains true until the field value changes (opposite of isDirty)
- isBlurred - Set after the field loses focus
Understanding isDirty Behavior
TanStack Form uses a persistent dirty state model. Once a field is changed, it remains dirty even if reverted to the default value. For non-persistent dirty behavior, use theisDefaultValue flag:
Field API
The Field API provides methods for managing field state. Access it through the template variable:Validation
Define validation rules at the field level using thevalidators prop:
Standard Schema Libraries
Use schema validation libraries that support the Standard Schema specification:Reactivity
Subscribe to form and field state changes usinginjectStore:
Listeners
React to specific field events by passing listener functions:Array Fields
Manage dynamic lists of values using array field methods:Array Field Methods
pushValue(value)- Add a new item to the endremoveValue(index)- Remove an item at indexswapValues(indexA, indexB)- Swap two itemsmoveValue(from, to)- Move an item to a new positioninsertValue(index, value)- Insert an item at indexreplaceValue(index, value)- Replace an item at indexclearValues()- Remove all items