Certain input elements contain properties that are used in basic form validation, such as required and maxLength. More complex validation logic is achieved using the properties and functions below.

Basic validation of elements against the constraints set in the Editor or programmatically is always performed, regardless of any custom validation.

However, sometimes more complex validation is needed, including validations that depend on more than one element. This is typically achieved by adding custom validation logic in an event handler that you set using the input element's onCustomValidation() function. Within that handler, you call the reject() function to indicate that the element is invalid. 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.

Keep in mind that custom validations with the onCustomValidation() event handler run after the onChange() event handler.

About Mixins

Mixins provide functionality that other elements can inherit and use.

Mixins are not elements. You cannot add mixins to a page in the Editor like other $w elements, and mixins are not meant to be used directly in your code.

For example, you would not write code like this, because it is out of context:


Instead, you can code the following if myElement is an element that "mixes in" ValidatableMixin.

Was this helpful?