new (require("bajaux/Validators"))(eventHandler)
- Description:
Manages a collection of Validator functions.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
eventHandler |
The associated eventHandler that has a 'trigger' method. |
Methods
add(validator) → {module:bajaux/Validators}
- Description:
Add a Validator function. This is used to validate
a read value before it can be saved.When a Validator function is invoked, the first argument will be the
value. If the function throws or returns a promise that rejects, the value
is considered to be invalid. If the function returns anything else
(including a promise that resolves), the value is considered to be valid.Please note, when saving a modified widget, the value will be read
from the widget, then validated and finally saved. Therefore, the
data passed into the validator for validation will the read data.
- Source:
- See:
Example
validators.add(function (value) {
if (!isAcceptable(value)) {
return Promise.reject(new Error('value not acceptable'));
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
validator |
function |
Returns:
get() → {Array}
- Description:
Return an array copy of the validators.
- Source:
- See:
Returns:
array of Validator functions.
- Type
- Array
remove(validator) → {module:bajaux/Validators}
- Description:
Remove a Validator function.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
validator |
function |
Returns:
validate(readValue) → {Promise}
- Description:
Called to validate some data. The read value run against each registered
Validator.To validate a widget, please call module:bajaux/Widget#validate
instead. This method will extract the read value and then call this method.This method should not be overridden. Instead Validators functions
should be added using module:bajaux/Validators#add.When saving a modified widget, the widget will be read, validated
and then saved. The read data is the current representation of
the widget and is passed to the validators. The read data will
not be the same as the loaded current value of the widget that
is used in the save process.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
readValue |
The read value that needs to be validated. |
Returns:
A promise to be resolved with the validated value
- Type
- Promise