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

The validate function (specified by you) is called as validate(inputToValidate, validationDone):

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):

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/); });