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 committed Mar 5, 2015
1 parent 2d0eda1 commit 5d39b2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,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;
parentForm.$setSubmitted();
if (!setOnChildren) {
parentForm.$setSubmitted();
}
forEach(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 @@ -410,6 +410,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(
'<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 5d39b2e

Please sign in to comment.