Search.../

onCustomValidation( )

Adds an event handler that runs when the element's validation is checked.

Description

The onCustomValidation() function allows you perform custom validation in addition to any basic validation that was defined in the Editor.

To invalidate the element, call the reject() function that is passed into the validator callback function and pass it a validation message.

The element's validity is checked when the value of the element changes either by user interaction or programmatically.

Note that validations other than required, including custom validations, are not run on input elements when they don't have a value.

Syntax

function onCustomValidation(validator: Validator): void
validator: function Validator(value: string | Array<File> | boolean, reject: Function): void

onCustomValidation Parameters

NAME
TYPE
DESCRIPTION
validator

Validator

The name of the function or the function expression to run when the element's custom validation is checked.

Returns

This function does not return anything.

Return Type:

void

Validator Parameters

NAME
TYPE
DESCRIPTION
value

string | Array<File> | boolean

The value of the element being validated.

reject

Function

A function that invalidates the element with the specified message.

Returns

This function does not return anything.

Return Type:

void
Mixed in from:$w.FormElement

Was this helpful?

Set an element to invalid if its value is "evil"

Code Example

Copy Code
1$w("#myElement").onCustomValidation( (value, reject) => {
2 if(value === "evil") {
3 reject("Evil is invalid");
4 }
5} );