blockly > Field > setValidator

Field.setValidator() method

Sets a new validation function for editable fields, or clears a previously set validator.

The validator function takes in the new field value, and returns validated value. The validated value could be the input value, a modified version of the input value, or null to abort the change.

If the function does not return anything (or returns undefined) the new value is accepted as valid. This is to allow for fields using the validated function as a field-level change event notification.


setValidator(handler: FieldValidator<T>): void;


Parameter Type Description
handler FieldValidator<T> The validator function or null to clear a previous validator.