Overview
Validation Manager (SK.ValidationManager) and Validator (SK.Validator) are helper classes that make field validation much easier. The Validation Manager accepts a form element as construction argument, searches for all fields that have validators metadata, attaches the validators to them and observes their value change in order to validate it. SK.ValidationManager class is used to bootstrap the validation and SK.Validator is an abstract class that wraps common functionality and it needs to be extended (used as base constructor) when creating validators.
Include Resource Files
Please note that the file dependencies may already exist in the environment and you may not need to include these.
/Shared/Scripts/validation_manager.js
<script type="text/javascript" src="/Shared/Scripts/validation_manager.js"></script>
Default Options
The Default Options represent an empty object. When Validation Manager is inititialized the events onSuccess and onError should be defined within the Default Options.
Methods
Name | Description | Parameters | Returns |
|---|---|---|---|
validate | Performs validation. | Mixed (the value to validate) | Object (Success or Error) |
getValidator | Returns Validator object by given name. | String (Validator's name) | Object (Validator) |
Events
Name | Description | Arguments |
|---|---|---|
onError | Fires an event when the validation fails. | Object (Validator), Object (DOMElement or Object implementing MooTools.Events) |
onSuccess | Fires an event when the validation is successfull (if onError event creates an element to display error message onSuccess event removes it.). | Object (Validator), Object (DOMElement or Object implementing MooTools.Events) |
List of Validators
Name | Description |
|---|---|
not-empty | Performs a non-empty string validation. |
number | Performs a number validation (valid values are 5, 1.095, "-0.8"). |
Examples
Init the Validation Manager, add not empty validator and create new validator for email: