From 5dbb08eebab1aaa1ce1251049e573f5a9bf39828 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 | 20 +++++++++++++++----- test/ng/directive/formSpec.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 28538806fef1..aee945cdc2c7 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -268,12 +268,22 @@ FormController.prototype = { * @name form.FormController#$setSubmitted * * @description - * Sets the form to its submitted state. + * Sets the form to its `$submitted` state. This will also set `$submitted` on all child and + * parent forms of the form. */ - $setSubmitted: function() { - this.$$animate.addClass(this.$$element, SUBMITTED_CLASS); - this.$submitted = true; - this.$$parentForm.$setSubmitted(); + $setSubmitted: function(onlySetOnChildren) { + this.$$animate.addClass(this.$$element, SUBMITTED_CLASS); + this.$submitted = true; + + if (!onlySetOnChildren) { + this.$$parentForm.$setSubmitted(); + } + + forEach(this.$$controls, function(control) { + if (control.$setSubmitted) { + control.$setSubmitted(true); + } + }); } }; diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index e1d681956b23..78ebe585cf82 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -527,6 +527,22 @@ describe('form', function() { expect(parent.$submitted).toBeTruthy(); }); + it('should set $submitted 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(