Skip to content

Commit 8ae27a5

Browse files
author
Caleb Kniffen
committed
fix(form): set $submitted to true on child forms when parent is submitted.
Closes angular#10071
1 parent b2f8b0b commit 8ae27a5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ng/directive/form.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,17 @@ function FormController(element, attrs, $scope, $animate, $interpolate) {
295295
* @description
296296
* Sets the form to its submitted state.
297297
*/
298-
form.$setSubmitted = function() {
298+
form.$setSubmitted = function(setOnChildren) {
299299
$animate.addClass(element, SUBMITTED_CLASS);
300300
form.$submitted = true;
301-
form.$$parentForm.$setSubmitted();
301+
if (!setOnChildren) {
302+
form.$$parentForm.$setSubmitted()
303+
}
304+
forEach(controls, function(control) {
305+
if (control.$setSubmitted) {
306+
control.$setSubmitted(true);
307+
}
308+
});
302309
};
303310
}
304311

test/ng/directive/formSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,22 @@ describe('form', function() {
523523
expect(parent.$submitted).toBeTruthy();
524524
});
525525

526+
it('should set $submitted equal to true on child forms when parent is submitted', function() {
527+
doc = jqLite(
528+
'<ng:form name="parent">' +
529+
'<ng:form name="child">' +
530+
'<input ng:model="modelA" name="inputA">' +
531+
'<input ng:model="modelB" name="inputB">' +
532+
'</ng:form>' +
533+
'</ng:form>');
534+
$compile(doc)(scope);
535+
536+
var parent = scope.parent,
537+
child = scope.child;
538+
539+
parent.$setSubmitted();
540+
expect(child.$submitted).toBeTruthy();
541+
});
526542

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

0 commit comments

Comments
 (0)