mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-06 22:35:22 +08:00
fix(forms): Set ng-valid/ng-invalid correctly
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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');
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user