# When validation runs

> Per-field validation triggers on `change`, `blur`, or `submit`: your call, per form. Sync refinements fire immediately; async refinements await.

Validation timing is configured per form via the `validateOn` option:

```ts
const form = useForm({
  schema,
  validateOn: 'change', // default
})
```

## Triggers

| Value                | Per-field validation fires on                                                                                                |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `'change'` (default) | Every committed write to storage. Pairs with the directive's commit cadence (per-keystroke by default, per-blur on `.lazy`). |
| `'blur'`             | When the input loses focus.                                                                                                  |
| `'submit'`           | Only when `handleSubmit` dispatches.                                                                                         |

The directive's commit cadence and the validation trigger are independent. With default `<input v-register>` and `validateOn: 'change'`, both fire per keystroke. Switch to `<input v-register.lazy>` and validation still rides the commit, which now lands on `change` (per-blur). Switch to `validateOn: 'blur'` and validation skips the per-write rhythm entirely.

The same schema runs in every mode: the only thing that changes is _when_ a refinement gets evaluated.

That is separate from when a person sees the result. An error is a property of the schema, not of the interaction, so [`field.firstError`](/docs/reading-the-form/errors) answers as soon as the mode validates. [`field.showErrors`](/docs/validation/showing-errors) is the display decision layered on top, and it waits for a submit attempt or a blur after interaction whatever `validateOn` says. Each panel below reports both.


Under `validateOn: 'blur'`, leaving a field you never edited can't change any verdict, so Attaform skips the pass. The comparison is per path, not per form: the blurred path's own subtree is measured against what was last validated there, so an edit somewhere else on the form does not make this blur re-run. Refocus a field that's showing an error, then tab away, and the error holds steady instead of blinking through `'pending'` and back.

One blur always runs regardless: the first one after the user actually edits the field. Type into a field, delete it back to what was there, and tab away, and that pass still fires even though the value is unchanged.

## Debouncing

Pass a `debounceMs` to coalesce rapid bursts:

```ts
useForm({
  schema,
  validateOn: 'change',
  debounceMs: 200,
})
```

The field's last committed write wins after `debounceMs` of quiet. Useful for expensive sync refinements; required for async refinements that hit a network (otherwise every keystroke fires a request).

`debounceMs` is only meaningful with `validateOn: 'change'`. TypeScript rejects pairing it with `'blur'` or `'submit'`, so a misconfigured form is a compile error rather than a silent runtime drop.

## Before the first trigger

A form knows its verdict on the values it starts with before any trigger fires. Attaform checks the starting value against the schema the first time anything reads or writes the form's errors: a template rendering `form.errors`, a submit button reading `form.meta.valid`, a wizard's step rail, the server serializing the form for the page. Every read sees the verdict it would have seen had the check run inside `useForm`, and a form nothing reads never runs its refinements, so a wizard pays for the step on screen rather than for every step it holds.

Two things follow from the timing. A refinement with a side effect, a log line or a dev warning, runs at that first read rather than inside `useForm`. And a client hydrating a server-rendered form takes the server's errors as its starting errors and runs no check of its own.

## Sync versus async

Sync refinements (`refine`, `superRefine` with synchronous returns) run on the trigger. Async refinements (anything that returns a Promise) are awaited:

- During typing (`validateOn: 'change'`), the field's `form.fields.<path>.validating` flips true while the Promise is in flight.
- On submit, `handleSubmit` waits for every active async refinement to settle before calling the success callback.
- `form.meta.valid` only flips true once every active path has resolved at least one validation pass, including the async ones. No flash-of-valid window.

## Where to next

- [Display state and showing errors](/docs/validation/showing-errors): when a field reveals its verdict.
- [`errors`](/docs/reading-the-form/errors): per-path error reads.
