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

fix(ngForm): don't clear validity of whole form when removing control #8863

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ function FormController(element, attrs, $scope, $animate) {
function clear(queue, validationToken) {
form.$setValidity(validationToken, true, control);
}

parentForm.$$clearControlValidity(form);
};

form.$$setPending = function(validationToken, control) {
Expand Down
29 changes: 29 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,35 @@ describe('form', function() {
expect(doc.find('div').hasClass('ng-valid-required')).toBe(true);
});

it('should leave the parent form invalid when deregister a removed input', function() {
doc = jqLite(
'<form name="parent">' +
'<div class="ng-form" name="child">' +
'<input ng-if="inputPresent" ng-model="modelA" name="inputA" required>' +
'<input ng-model="modelB" name="inputB" required>' +
'</div>' +
'</form>');
$compile(doc)(scope);
scope.inputPresent = true;
scope.$apply();

var parent = scope.parent,
child = scope.child,
inputA = child.inputA,
inputB = child.inputB;

expect(parent).toBeDefined();
expect(child).toBeDefined();
expect(parent.$error.required).toEqual([child]);
expect(child.$error.required).toEqual([inputB, inputA]);

//remove child input
scope.inputPresent = false;
scope.$apply();

expect(parent.$error.required).toEqual([child]);
expect(child.$error.required).toEqual([inputB]);
});

it('should chain nested forms in repeater', function() {
doc = jqLite(
Expand Down