Adding new event listeners - mosbymc/validator GitHub Wiki

Wiring the validator to listen for additional events

When initialized, by default, the validator will listen for the input event on dom inputs for single input validation. If you would like to have the validator listen to other events for validating a single input, you simply need to pass an array of the event types to the validator upon initialization like so:

validator.setAdditionalEvents(["change"])`

The example above will wire up the validator to listen for the change event on inputs, however, you can pass in any input event you'd like the validator to listen for when validating an input.

Configuring the input

Also by default, all inputs with the 'inputValidate' class will be validated on the input event. To make the input be validated on one of the other events you passed into the validator initialization, add an attribute called 'data-validateon' and give it a value of the event type you want it to be validated on. Using the "change" event passed into the validator above, to make an input be validated on the change event, you'd simply add: data-validateon="change" to the element.

Note that an input can only be validated on one event type at a time. If you set up an input to be validate on the change event, it will no longer be validated on the input event.

Continue to: Call before validation function