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 | |
| parent | 7c8a2ccb8d7b595419dfbe9151928cd2533550e3 (diff) | |
| download | angular.js-3f9a2ab9bdfcd12cb7df74b0d38cecf2ee4ac94a.tar.bz2 | |
added asynchronous validator
Diffstat (limited to 'src')
| -rw-r--r-- | src/Parser.js | 4 | ||||
| -rw-r--r-- | src/Validators.js | 29 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/Parser.js b/src/Parser.js index 3aa644ac..b59b21a7 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -349,11 +349,11 @@ Parser.prototype = { }, filter: function(){ - return this._pipeFunction(angular['filter']); + return this._pipeFunction(angularFilter); }, validator: function(){ - return this._pipeFunction(angular['validator']); + return this._pipeFunction(angularValidator); }, _pipeFunction: function(fnScope){ 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;}); |
