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.
You can use the override
parameter to override previously applied custom validations.
Authorization
Request
This endpoint does not take any parameters
Status/Error Codes
Was this helpful?
1$w("#myElement").onCustomValidation( (value, reject) => {2 if(value === "evil") {3 reject("Evil is invalid");4 }5} );
1// This validation won't run2$w("#myElement").onCustomValidation( (value, reject) => {3 if(value === "evil") {4 reject("Evil is invalid");5 }6}, false);78// This validation will run9$w("#myElement").onCustomValidation( (value, reject) => {10 if(value === "bad") {11 reject("Bad is invalid");12 }13}, true);
In this example, only the 3rd and 4th custom validations run. This is because the override property for the 3rd validation is set to true by default and overrides the previous 2 validations.
1// This validation won't run2$w("#myElement").onCustomValidation( (value, reject) => {3 if(value === "ain't") {4 reject("Ain't is invalid");5 }6}, false);78// This validation won't run9$w("#myElement").onCustomValidation( (value, reject) => {10 if(value === "i'd've") {11 reject("I'd've is invalid");12 }13}, true);1415// This validation runs first16$w("#myElement").onCustomValidation( (value, reject) => {17 if(value === "there're") {18 reject("There're is invalid");19 }20});2122// This validation runs second23$w("#myElement").onCustomValidation( (value, reject) => {24 if(value === "could've") {25 reject("Could've is invalid");26 }27}, false);