Module: JSE/Extensions/validator

Validator Extension

Validate form elements for common rules such as required fields, email addresses and other useful premade types. You can add new validation types by appending the list in the end of this file.

Methods

$parent.trigger('validator.validate'); // Trigger validation manually.
$parent.trigger('validator.reset'); // Reset validator state.

Example Usage

The following element will be validated as a required field and the value must be a valid email address (two validation rules).

<div id="parent" data-gx-extension="validator">
  <input type="email" class="validate" data-validator-validate="required email" />
</div>

The following script demonstrates how to check if there are currently invalid elements in the form.

// Trigger validation manually:
$('#parent').trigger('validator.validate');

// Check for invalid field values.
if ($('#parent .error').length > 0) {
     // Invalid elements have the ".error" class.
} else {
     // Valid input elements have the ".valid" class.
}
Source: