Skip to content

Trigger Plugin

Attaches DOM event listeners to form fields and triggers validation when they fire.

Options

OptionTypeDefaultDescription
eventstring | Record<string, string | false>"input"DOM event name(s) to listen to. Use a record to set per-field events. Set to false to disable a field.
delaynumber0Debounce delay in milliseconds before triggering validation

Playground

Debouncing

Use delay to avoid validating on every keystroke — the timer resets with each event and validation only fires after the user stops typing:

js
new Trigger({ event: 'input', delay: 300 })

You can combine different events and a delay:

js
new Trigger({
  event: { email: 'blur', username: 'input' },
  delay: 400,   // applies to all fields
})

blur events rarely need a delay — validation on blur fires once when the user leaves the field. Debounce is most useful with input and change.

Notes

  • Without Trigger, validation only runs when you call fv.validate() or fv.validateField() manually.
  • Events are attached on core.field.added and cleaned up on core.field.removed.
  • For remote validators that make network requests, always set a delay to avoid a request per keystroke.

Released under the MIT License.