mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 15:24:43 +00:00
fix(forms): Set ng-valid/ng-invalid correctly
This commit is contained in:
parent
f13dd3393d
commit
08bfea183a
2 changed files with 15 additions and 7 deletions
|
|
@ -800,22 +800,21 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', '$e
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
if ($error[validationErrorKey]) invalidCount--;
|
if ($error[validationErrorKey]) invalidCount--;
|
||||||
$error[validationErrorKey] = false;
|
|
||||||
toggleValidCss(isValid);
|
|
||||||
if (!invalidCount) {
|
if (!invalidCount) {
|
||||||
toggleValidCss(isValid, validationErrorKey);
|
toggleValidCss(true);
|
||||||
this.$valid = true;
|
this.$valid = true;
|
||||||
this.$invalid = false;
|
this.$invalid = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!$error[validationErrorKey]) invalidCount++;
|
toggleValidCss(false)
|
||||||
$error[validationErrorKey] = true;
|
|
||||||
toggleValidCss(isValid)
|
|
||||||
toggleValidCss(isValid, validationErrorKey);
|
|
||||||
this.$invalid = true;
|
this.$invalid = true;
|
||||||
this.$valid = false;
|
this.$valid = false;
|
||||||
|
invalidCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$error[validationErrorKey] = !isValid;
|
||||||
|
toggleValidCss(isValid, validationErrorKey);
|
||||||
|
|
||||||
parentForm.$setValidity(validationErrorKey, isValid, this);
|
parentForm.$setValidity(validationErrorKey, isValid, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,15 @@ describe('ng-model', function() {
|
||||||
|
|
||||||
dealoc(element);
|
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');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue