Skip to content

AutoFocus Plugin

Automatically focuses the first invalid field when form validation fails, improving keyboard navigation and accessibility.

Options

OptionTypeDefaultDescription
enabledbooleantrueEnable or disable the plugin
onPrefocusfunctionundefinedCalled 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 by fv.validate(), not by fv.validateField().
  • Use onPrefocus to scroll to the field, show a toast, or log analytics before focus occurs.
  • Compatible with the Aria plugin — combining both gives full keyboard and screen reader accessibility.
  • Field statuses are cleared at the start of each validate() call and re-tracked fresh.

Released under the MIT License.