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.
validate –
{function(inputToValidate,validationDone)}
– function to call to validate the state
of the input.
update –
{function(data)=}[noop]
– function to call when state of the
validator changes
The validate function (specified by you) is called as
validate(inputToValidate, validationDone):
inputToValidate: value of the input box.
validationDone: function(error, data){...}
error: error text to display if validation fails
data: data object to pass to update function
The update function is optionally specified by you and is
called by <angular/> on input change. Since the
asynchronous validator caches the results, the update
function can be called without a call to validate
function. The function is called as update(data):
data: data object as passed from validate function
CSS
ng-input-indicator-wait, ng-validation-error
Example
<script>
function myValidator(inputToValidate, validationDone) {
setTimeout(function(){
validationDone(inputToValidate.length % 2);
}, 500);
}
</script>
This input is validated asynchronously:
<input name="text" ng:validate="asynchronous:$window.myValidator">
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/);
});