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

Commit

Permalink
fix(form): set $submitted to true on child forms when parent is submi…
Browse files Browse the repository at this point in the history
…tted.

Closes #10071
  • Loading branch information
Caleb Kniffen authored and Narretz committed Mar 6, 2017
1 parent 603b66e commit 5dbb08e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
};

Expand Down
16 changes: 16 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<ng-form name="parent">' +
'<ng-form name="child">' +
'<input ng:model="modelA" name="inputA">' +
'<input ng:model="modelB" name="inputB">' +
'</ng-form>' +
'</ng-form>');
$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(
Expand Down

0 comments on commit 5dbb08e

Please sign in to comment.