aboutsummaryrefslogtreecommitdiffstats
path: root/src/Validators.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/Validators.js')
-rw-r--r--src/Validators.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Validators.js b/src/Validators.js
index 84681f15..b7efcb4a 100644
--- a/src/Validators.js
+++ b/src/Validators.js
@@ -77,5 +77,34 @@ foreach({
} catch (e) {
return e.toString();
}
+ },
+
+ 'asynchronous': function(text, asynchronousFn) {
+ var stateKey = '$validateState';
+ var lastKey = '$lastKey';
+ var obj = this['$element'];
+ var stateCache = obj[stateKey] = obj[stateKey] || {};
+ var state = stateCache[text];
+ var updateView = this['$updateView'];
+ obj[lastKey] = text;
+ if (state === undefined) {
+ // we have never seen this before, Request it
+ jQuery(obj).addClass('ng-input-indicator-wait');
+ state = stateCache[text] = null;
+ asynchronousFn(text, function(error){
+ state = stateCache[text] = error ? error : false;
+ if (stateCache[obj[lastKey]] !== null) {
+ jQuery(obj).removeClass('ng-input-indicator-wait');
+ }
+ updateView();
+ });
+ }
+
+ if (state === null){
+ // request in flight, mark widget invalid, but don't show it to user
+ this['$invalidWidgets'].push(this.$element);
+ }
+ return state;
}
+
}, function(v,k) {angularValidator[k] = v;});