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

Commit 28f69af

Browse files
Caleb KniffenNarretz
authored andcommitted
fix(form): set $submitted to true on child forms when parent is submitted.
Closes #10071
1 parent 181ac0b commit 28f69af

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/ng/directive/form.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,22 @@ FormController.prototype = {
274274
* @name form.FormController#$setSubmitted
275275
*
276276
* @description
277-
* Sets the form to its submitted state.
277+
* Sets the form to its `$submitted` state. This will also set `$submitted` on all child and
278+
* parent forms of the form.
278279
*/
279-
$setSubmitted: function() {
280-
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
281-
this.$submitted = true;
282-
this.$$parentForm.$setSubmitted();
280+
$setSubmitted: function(onlySetOnChildren) {
281+
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
282+
this.$submitted = true;
283+
284+
if (!onlySetOnChildren) {
285+
this.$$parentForm.$setSubmitted();
286+
}
287+
288+
forEach(this.$$controls, function(control) {
289+
if (control.$setSubmitted) {
290+
control.$setSubmitted(true);
291+
}
292+
});
283293
}
284294
};
285295

test/ng/directive/formSpec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,22 @@ describe('form', function() {
539539
expect(parent.$submitted).toBeTruthy();
540540
});
541541

542+
it('should set $submitted to true on child forms when parent is submitted', function() {
543+
doc = jqLite(
544+
'<ng-form name="parent">' +
545+
'<ng-form name="child">' +
546+
'<input ng:model="modelA" name="inputA">' +
547+
'<input ng:model="modelB" name="inputB">' +
548+
'</ng-form>' +
549+
'</ng-form>');
550+
$compile(doc)(scope);
551+
552+
var parent = scope.parent,
553+
child = scope.child;
554+
555+
parent.$setSubmitted();
556+
expect(child.$submitted).toBeTruthy();
557+
});
542558

543559
it('should deregister a child form when its DOM is removed', function() {
544560
doc = jqLite(

0 commit comments

Comments
 (0)