diff options
| author | Misko Hevery | 2010-02-12 19:39:01 -0800 |
|---|---|---|
| committer | Misko Hevery | 2010-02-12 19:39:01 -0800 |
| commit | 3f9a2ab9bdfcd12cb7df74b0d38cecf2ee4ac94a (patch) | |
| tree | ac3e6197c742a0771350fe8e15c8d53b85d447c3 /src/Validators.js | |
| parent | 7c8a2ccb8d7b595419dfbe9151928cd2533550e3 (diff) | |
| download | angular.js-3f9a2ab9bdfcd12cb7df74b0d38cecf2ee4ac94a.tar.bz2 | |
added asynchronous validator
Diffstat (limited to 'src/Validators.js')
| -rw-r--r-- | src/Validators.js | 29 |
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;}); |
