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.
Syntax
function onCustomValidation(validator: RadioButtonGroupValidator, [override: boolean]): voidvalidator: function RadioButtonGroupValidator(value: string, reject: Function): void
onCustomValidation Parameters
NAME
TYPE
DESCRIPTION
The name of the function or the function expression to run when the element's custom validation is checked.
When true
, overrides any existing custom validations set for the element so that only the current custom validation applies.
When false
, the current custom validation is added to the previously applied validations and all of them run. The order of execution follows the order the validations were set.
If one of the validations rejects, the rest of the validations won't run.
Defaults to true
, so that omitting the override
property causes the current custom validation to override any other validations.
If multiple validations are set to override explicitly or by default, only the last applied validation will run.
For example, if you add 4 custom validations to an element and set the override
parameter to false
, true
, false
, false
respectively, the first validation won't run
and the remaining validations will run. This is because the second validation overrides the first.
Returns
This function does not return anything.
Return Type:
RadioButtonGroupValidator Parameters
NAME
TYPE
DESCRIPTION
The value of the element being validated. The value type differs depending on the input element.
For example, the value type for a TextInput
validator is a string, and the value type for an UploadButton
is an array of File
objects.
A function that invalidates the element with the specified message.
Returns
This function does not return anything.
Return Type:
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);