aboutsummaryrefslogtreecommitdiffstats
path: root/src/validators.js
diff options
context:
space:
mode:
authorMisko Hevery2010-11-04 17:41:14 -0700
committerMisko Hevery2010-11-05 13:32:37 -0700
commit3d6a099d6e40f1e12f6349843218987d472d0f3c (patch)
tree5adf8b44fb57767ab6fcb3a046b3e421217dfdb2 /src/validators.js
parent8767e766d13b7d3a1e3b6b06f3030c843d3b19ba (diff)
downloadangular.js-3d6a099d6e40f1e12f6349843218987d472d0f3c.tar.bz2
changed to showdown from markup. added validator overview
Diffstat (limited to 'src/validators.js')
-rw-r--r--src/validators.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/validators.js b/src/validators.js
index fd18d66c..a1543f41 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -84,6 +84,62 @@ extend(angularValidator, {
}
},
+ /**
+ * @ngdoc validator
+ * @name angular.validator.asynchronous
+ * @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.
+ *
+ * @param {string} value value to validate
+ * @param {function(inputToValidate,validationDone)} validate function to call to validate the state
+ * of the input.
+ * @param {function(data)=} [update=noop] function to call when state of the
+ * validator changes
+ *
+ * @paramDescription
+ * 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
+ *
+ * @exampleDescription
+ * <pre>
+ * function myValidator (value, callback) {
+ * // simulate delayed response, validate on even input length
+ * setTimeout(function(){
+ * callback(value.length % 2);
+ * }, 2000);
+ * };
+ * </pre>
+ *
+ * @example
+ * <script>
+ * function myValidator(value, callback) {
+ * setTimeout(function(){
+ * callback(value.length % 2);
+ * }, 2000);
+ * }
+ * </script>
+ * This input is validated asynchronously:
+ * <input name="text" ng:validate="asynchronous:$window.myValidator">
+ *
+ */
/*
* cache is attached to the element
* cache: {