@tanstack/solid-form. Understanding these concepts will help you work effectively with the library.
Form Options
You can create reusable form options that can be shared between multiple forms using theformOptions function:
Form Instance
A Form Instance represents an individual form and provides methods and properties for working with it. You create a form instance using thecreateForm hook.
Using createForm with formOptions
Standalone createForm
You can also create a form instance without usingformOptions:
The
createForm hook in Solid accepts a function that returns the configuration. This is important for proper reactivity.Field
A Field represents a single form input element. Fields are created using theform.Field component with a render prop pattern:
In Solid, the
field parameter is a function that returns the field API. Always call it as field() to access the current state and methods.Field State
Each field has its own state with metadata about the field’s current status:Field Metadata States
There are four key states that track user interaction:isTouched- Set after the user changes the field or blurs itisDirty- Set after the field’s value has been changed (even if reverted). Opposite ofisPristineisPristine- True until the user changes the field value. Opposite ofisDirtyisBlurred- Set after the field has been blurred
Understanding ‘isDirty’ States
TanStack Form uses a persistentdirty state model:
Persistent dirty state (TanStack Form)
- A field remains ‘dirty’ once changed, even if reverted to the default value
- Similar to Angular Form and Vue FormKit
dirty state (Other libraries)
- A field is ‘dirty’ only if its value differs from the default
- Used by React Hook Form, Formik, and Final Form
isDefaultValue flag:
Field API
The Field API provides methods for working with the field’s state:handleChange(value)- Update the field valuehandleBlur()- Mark the field as blurredstate.value- Access the current valuestate.meta- Access field metadata
Validation
@tanstack/solid-form provides both synchronous and asynchronous validation:
Validation with Standard Schema Libraries
TanStack Form supports the Standard Schema specification:- Zod (v3.24.0 or higher)
- Valibot (v1.0.0 or higher)
- ArkType (v2.1.20 or higher)
- Yup (v1.7.0 or higher)
Reactivity
@tanstack/solid-form offers multiple ways to subscribe to form and field state changes:
Using form.useStore
Using form.Subscribe
Array Fields
Array fields allow you to manage lists of values within a form. Use themode="array" prop:
pushValue(value)- Add an item to the endremoveValue(index)- Remove an item at indexswapValues(indexA, indexB)- Swap two itemsmoveValue(from, to)- Move an item from one index to anotherinsertValue(index, value)- Insert at a specific indexreplaceValue(index, value)- Replace an item at indexclearValues()- Remove all items
Next Steps
- Validation - Deep dive into form validation
- Arrays - Learn more about working with array fields