Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fixup! fix(required): correctly validate when required on non-input e…
Browse files Browse the repository at this point in the history
…lement is surrounded by ngIf
  • Loading branch information
Narretz committed Mar 6, 2019
1 parent 9be1198 commit 2cdae38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/directive/validators.js
Expand Up @@ -69,7 +69,7 @@ var requiredDirective = ['$parse', function($parse) {
link: function(scope, elm, attr, ctrl) {
if (!ctrl) return;
// For boolean attributes like required, presence means true
var value = 'required' in attr || $parse(attr.ngRequired)(scope);
var value = attr.hasOwnProperty('required') || $parse(attr.ngRequired)(scope);

if (!attr.ngRequired) {
// force truthy in case we are on non input element
Expand Down
7 changes: 7 additions & 0 deletions test/ng/directive/validatorsSpec.js
Expand Up @@ -696,6 +696,13 @@ describe('validators', function() {
}));


it('should override "required" when ng-required="false" is set', function() {
var inputElm = helper.compileInput('<input type="text" ng-model="notDefined" required ng-required="false" />');

expect(inputElm).toBeValid();
});


it('should validate only once after compilation when inside ngRepeat', function() {
helper.compileInput(
'<div ng-repeat="input in [0]">' +
Expand Down

0 comments on commit 2cdae38

Please sign in to comment.