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(