From e549f2d70c93ce402d781bc16b557b5950b2cbb3 Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Tue, 10 Feb 2015 12:55:08 -0600 Subject: [PATCH] fix(form): set $submitted to true on child forms when parent is submitted. Closes #10071 --- src/ng/directive/form.js | 11 +++++++++-- test/ng/directive/formSpec.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 298c66ea183a..aa23114715c3 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -295,10 +295,17 @@ function FormController(element, attrs, $scope, $animate, $interpolate) { * @description * Sets the form to its submitted state. */ - form.$setSubmitted = function() { + form.$setSubmitted = function(setOnChildren) { $animate.addClass(element, SUBMITTED_CLASS); form.$submitted = true; - form.$$parentForm.$setSubmitted(); + if (!setOnChildren) { + form.$$parentForm.$setSubmitted(); + } + forEach(controls, function(control) { + if (control.$setSubmitted) { + control.$setSubmitted(true); + } + }); }; } diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index 95a0fdeb1cc7..bbff75c1dd40 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -523,6 +523,22 @@ describe('form', function() { expect(parent.$submitted).toBeTruthy(); }); + it('should set $submitted equal to true on child forms when parent is submitted', function() { + doc = jqLite( + '' + + '' + + '' + + '' + + '' + + ''); + $compile(doc)(scope); + + var parent = scope.parent, + child = scope.child; + + parent.$setSubmitted(); + expect(child.$submitted).toBeTruthy(); + }); it('should deregister a child form when its DOM is removed', function() { doc = jqLite(