Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,17 @@ function FormController(element, attrs, $scope, $animate, $interpolate) {
* @description
* Sets the form to its submitted state.
*/
form.$setSubmitted = function() {
form.$setSubmitted = function(setOnChildren) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name it something more descriptive (e.g. propagateToChildrenOnly or skipPropagationToParent or something).
(setOnChildren made me think we'll always update the parent and we're wondering about the children.)

We should also improve the description, mentioning that it will propagate to parent and children.

Should the arg be public (aka documented).

$animate.addClass(element, SUBMITTED_CLASS);
form.$submitted = true;
form.$$parentForm.$setSubmitted();
if (!setOnChildren) {
form.$$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 @@ -523,6 +523,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