From 953ee22f76f8c1137949ed07f36fafc5bbfeb7fe Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Sat, 30 Aug 2014 14:24:30 +0300 Subject: [PATCH] fix(ngForm): don't clear validity of whole form when removing control Calling `$$clearControlValidity` on the parent of a nested form caused the parent form to look like there are no more errors on the nested form even if it still had some inputs with errors. there is no need to call this method recursively since `$setValidity` will propagate the new validity state well enough. Closes #8863 --- src/ng/directive/form.js | 2 -- test/ng/directive/formSpec.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 556377c7..1afede72 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -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) { diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index 2a965795..e780c615 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -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( + '
' + + '
' + + '' + + '' + + '
' + + '
'); + $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(