AutoFocus Plugin
Automatically focuses the first invalid field when form validation fails, improving keyboard navigation and accessibility.
Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable the plugin |
onPrefocus | function | undefined | Called before focusing: ({ field, element }) => void |
Playground
Submit the form with empty fields — the cursor jumps to the first invalid input automatically. The status line shows which field was focused.
Notes
- Focuses the first invalid field in the order they were defined in
fields. - Only fires on
core.form.invalid— triggered byfv.validate(), not byfv.validateField(). - Use
onPrefocusto scroll to the field, show a toast, or log analytics before focus occurs. - Compatible with the
Ariaplugin — combining both gives full keyboard and screen reader accessibility. - Field statuses are cleared at the start of each
validate()call and re-tracked fresh.