angular.validator.asynchronous
Work in Progress
This page is currently being revised. It might be incomplete or contain inaccuracies.
Description
Use asynchronous validator if the validation can not be computed
immediately, but is provided through a callback. The widget
automatically shows a spinning indicator while the validity of
the widget is computed. This validator caches the result.
Usage
In HTML Template Binding
<input type="text" ng:validate="asynchronous:validate[:update]"/>
In JavaScript
angular.validator.asynchronous(value, validate[, update])
Parameters
value – {string} –
value to validate
validate – {function(inputToValidate,validationDone)} –
function to call to validate the state
of the input.
update(optional=noop) – {function(data)} –
function to call when state of the
validator changes
Example
<script>
function MyCntl(){
this.myValidator = function (inputToValidate, validationDone) {
setTimeout(function(){
validationDone(inputToValidate.length % 2);
}, 500);
}
}
</script>
This input is validated asynchronously:
<div ng:controller="MyCntl">
<input name="text" ng:validate="asynchronous:myValidator">
</div>
it('should change color in delayed way', function(){
var textBox = element('.doc-example :input');
expect(textBox.attr('className')).not().toMatch(/ng-input-indicator-wait/);
expect(textBox.attr('className')).not().toMatch(/ng-validation-error/);
input('text').enter('X');
expect(textBox.attr('className')).toMatch(/ng-input-indicator-wait/);
pause(.6);
expect(textBox.attr('className')).not().toMatch(/ng-input-indicator-wait/);
expect(textBox.attr('className')).toMatch(/ng-validation-error/);
});