diff options
| author | Vojta Jina | 2012-03-15 17:17:23 -0700 |
|---|---|---|
| committer | Vojta Jina | 2012-03-16 12:06:29 -0700 |
| commit | 08bfea183a850b29da270eac47f80b598cbe600f (patch) | |
| tree | d4a09ffa9dfa601608730b0de6309718e4612adb | |
| parent | f13dd3393dfb7a33565c9360342c193bc0bddcb6 (diff) | |
| download | angular.js-08bfea183a850b29da270eac47f80b598cbe600f.tar.bz2 | |
fix(forms): Set ng-valid/ng-invalid correctly
| -rw-r--r-- | src/directive/input.js | 13 | ||||
| -rw-r--r-- | test/directive/inputSpec.js | 9 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/directive/input.js b/src/directive/input.js index 631e3a36..2e1c7fff 100644 --- a/src/directive/input.js +++ b/src/directive/input.js @@ -800,22 +800,21 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', '$e if (isValid) { if ($error[validationErrorKey]) invalidCount--; - $error[validationErrorKey] = false; - toggleValidCss(isValid); if (!invalidCount) { - toggleValidCss(isValid, validationErrorKey); + toggleValidCss(true); this.$valid = true; this.$invalid = false; } } else { - if (!$error[validationErrorKey]) invalidCount++; - $error[validationErrorKey] = true; - toggleValidCss(isValid) - toggleValidCss(isValid, validationErrorKey); + toggleValidCss(false) this.$invalid = true; this.$valid = false; + invalidCount++; } + $error[validationErrorKey] = !isValid; + toggleValidCss(isValid, validationErrorKey); + parentForm.$setValidity(validationErrorKey, isValid, this); }; diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index ad1670f9..2a7244c9 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -269,6 +269,15 @@ describe('ng-model', function() { dealoc(element); })); + + + it('should set invalid classes on init', inject(function($compile, $rootScope) { + var element = $compile('<input type="email" ng-model="value" required />')($rootScope); + $rootScope.$digest(); + + expect(element).toBeInvalid(); + expect(element).toHaveClass('ng-invalid-required'); + })); }); |
