aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js10
-rw-r--r--src/Compiler.js1
-rw-r--r--src/Validators.js31
-rw-r--r--src/Widgets.js8
4 files changed, 28 insertions, 22 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 12293ddb..e49eb9a9 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -228,6 +228,16 @@ function escapeHtml(html) {
replace(/>/g, '>');
}
+function elementDecorateError(element, error) {
+ if (error) {
+ element.addClass(NG_VALIDATION_ERROR);
+ element.attr(NG_ERROR, error);
+ } else {
+ element.removeClass(NG_VALIDATION_ERROR);
+ element.removeAttr(NG_ERROR);
+ }
+}
+
function escapeAttr(html) {
if (!html || !html.replace)
return html;
diff --git a/src/Compiler.js b/src/Compiler.js
index 923f7b2f..e97fb112 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -93,6 +93,7 @@ Compiler.prototype = {
rawElement = jqLite(rawElement);
var template = this.templatize(rawElement) || new Template();
return function(element, parentScope){
+ element = jqLite(element);
parentScope = parentScope || {};
var scope = createScope(parentScope);
parentScope.$root = parentScope.$root || scope;
diff --git a/src/Validators.js b/src/Validators.js
index 662145c0..ecf21a01 100644
--- a/src/Validators.js
+++ b/src/Validators.js
@@ -82,29 +82,30 @@ foreach({
},
'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;
+ var element = this['$element'];
+ var cache = element.data('$validateState');
+ if (!cache) {
+ cache = { state: {}};
+ element.data('$validateState', cache);
+ }
+ var state = cache.state[text];
+ cache.lastKey = text;
if (state === undefined) {
// we have never seen this before, Request it
- jqLite(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) {
- jqLite(obj).removeClass('ng-input-indicator-wait');
+ element.addClass('ng-input-indicator-wait');
+ state = cache.state[text] = null;
+ (asynchronousFn || noop)(text, function(error){
+ state = cache.state[text] = error ? error : false;
+ if (cache.state[cache.lastKey] !== null) {
+ element.removeClass('ng-input-indicator-wait');
}
- updateView();
+ elementDecorateError(element, error);
});
}
if (state === null){
// request in flight, mark widget invalid, but don't show it to user
- this['$invalidWidgets'].push(this.$element);
+ (this['$invalidWidgets']||[]).push(this.$element);
}
return state;
}
diff --git a/src/Widgets.js b/src/Widgets.js
index b5222ac7..870468d3 100644
--- a/src/Widgets.js
+++ b/src/Widgets.js
@@ -28,13 +28,7 @@ function valueAccessor(scope, element) {
function validate(value) {
var error = required && !trim(value) ? "Required" : validator({self:scope, scope:{get:scope.$get, set:scope.$set}}, value);
if (error !== lastError) {
- if (error) {
- element.addClass(NG_VALIDATION_ERROR);
- element.attr(NG_ERROR, error);
- } else {
- element.removeClass(NG_VALIDATION_ERROR);
- element.removeAttr(NG_ERROR);
- }
+ elementDecorateError(element, error);
lastError = error;
}
return value;