diff options
| author | Misko Hevery | 2010-04-16 14:01:29 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-16 14:01:29 -0700 |
| commit | deb86fe357a901889bc4289087f0b9e69cb8a302 (patch) | |
| tree | fce4db8501a6c24430d611c95a4aa001119c7b89 /src/widgets.js | |
| parent | 70e401ef100614295fc808e32f0142f07c315461 (diff) | |
| download | angular.js-deb86fe357a901889bc4289087f0b9e69cb8a302.tar.bz2 | |
lots of small fixes
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/widgets.js b/src/widgets.js index 09b602af..2909aed1 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -27,6 +27,11 @@ function valueAccessor(scope, element) { required = required || required === ''; if (!validator) throw "Validator named '" + validatorName + "' not found."; function validate(value) { + if (element[0].disabled || isString(element.attr('readonly'))) { + elementError(element, NG_VALIDATION_ERROR, null); + invalidWidgets.markValid(element); + return value; + } var error, validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element}); error = required && !trim(value) ? @@ -42,6 +47,7 @@ function valueAccessor(scope, element) { } return value; } + element.data('$validate', validate); return { get: function(){ return validate(element.val()); }, set: function(value){ element.val(validate(value)); } @@ -167,20 +173,31 @@ angularWidget('SELECT', function(element){ angularWidget('NG:INCLUDE', function(element){ var compiler = this, - src = element.attr("src"); - if (element.attr('switch-instance')) { + srcExp = element.attr("src"), + scopeExp = element.attr("scope") || ''; + if (element[0]['ng-compiled']) { this.descend(true); this.directives(true); } else { + element[0]['ng-compiled'] = true; return function(element){ var scope = this, childScope; - element.attr('switch-instance', 'compiled'); - scope.$browser.xhr('GET', src, function(code, response){ - element.html(response); - childScope = createScope(scope); - compiler.compile(element)(element, childScope); - childScope.$init(); - scope.$root.$eval(); + var changeCounter = 0; + function incrementChange(){ changeCounter++;} + this.$watch(srcExp, incrementChange); + this.$watch(scopeExp, incrementChange); + this.$watch(function(){return changeCounter;}, function(){ + var src = this.$eval(srcExp), + useScope = this.$eval(scopeExp); + if (src) { + scope.$browser.xhr('GET', src, function(code, response){ + element.html(response); + childScope = useScope || createScope(scope); + compiler.compile(element)(element, childScope); + childScope.$init(); + scope.$root.$eval(); + }); + } }); scope.$onEval(function(){ if (childScope) childScope.$eval(); |
