Event handler
A Validation
object can be used as an event handler. When executed on the client side, it is just a wrapper over the Validation().validate()
method and can be passed directly into the addEventListener()
method.
Syntax
Parameters
event
optional
AnEvent
object. (Only the propertytarget
is used to validate predicate groups associated with the object it refers to.)
Default:undefined
.
Return value
See “Return value” of the Validation().validate()
method.
Exceptions
See “Exceptions” of the Validation().validate()
method.
Description
Using a Validation
object as an event handler is intended to reduce boilerplate.
Examples
Validation
as an event handler
Consider the code below. The grouping Validation
object was added as an event handler
form.addEventListener('input', validation);
instead of creating an event handler function
form.addEventListener('input', (event) => validation.validate(event.target));
Depending on your code style, you could even define the whole Validation
without assigning it to a variable and instead pass it right immediately into the addEventListener()
method: