Overview
formAtom(initial, validators?) extends atom with sync validation. Validators are a ValidatorFn[] or a factory () => ValidatorFn[] re-read on every check (so rules can close over other fields).
.errors stays [] until the field is dirty or you call validate(). .isValid is a live getter that re-runs validators without writing .errors or marking dirty.
Async validators are not supported — a Promise-returning rule throws. Use schema / validateObject for I/O checks.
formAtom vs atom vs schema
|
API
|
Role
|
Prefer when
|
|---|---|---|
formAtom
| Field + sync validate | Inputs with inline errors |
atom
| Plain reactive cell | No built-in validation |
schema
| Plain snapshot | Submit / server; async OK |
Bind inputs to formAtom
set() marks dirty and runs sync validators. Show errors when dirty.
errors, isValid, dirty, reset
isValid re-runs without writing errors. validate() marks dirty. resetValidation() clears both.
Cross-field — factory validators
Pass () => [...] so confirm can read password() on every check. isEqualTo takes a getter.
Numeric helpers
toFloat, toFloatString, and toValidNumber parse without changing the atom.