File tree 2 files changed +31
-5
lines changed 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -268,12 +268,22 @@ FormController.prototype = {
268
268
* @name form.FormController#$setSubmitted
269
269
*
270
270
* @description
271
- * Sets the form to its submitted state.
271
+ * Sets the form to its `$submitted` state. This will also set `$submitted` on all child and
272
+ * parent forms of the form.
272
273
*/
273
- $setSubmitted : function ( ) {
274
- this . $$animate . addClass ( this . $$element , SUBMITTED_CLASS ) ;
275
- this . $submitted = true ;
276
- this . $$parentForm . $setSubmitted ( ) ;
274
+ $setSubmitted : function ( onlySetOnChildren ) {
275
+ this . $$animate . addClass ( this . $$element , SUBMITTED_CLASS ) ;
276
+ this . $submitted = true ;
277
+
278
+ if ( ! onlySetOnChildren ) {
279
+ this . $$parentForm . $setSubmitted ( ) ;
280
+ }
281
+
282
+ forEach ( this . $$controls , function ( control ) {
283
+ if ( control . $setSubmitted ) {
284
+ control . $setSubmitted ( true ) ;
285
+ }
286
+ } ) ;
277
287
}
278
288
} ;
279
289
Original file line number Diff line number Diff line change @@ -527,6 +527,22 @@ describe('form', function() {
527
527
expect ( parent . $submitted ) . toBeTruthy ( ) ;
528
528
} ) ;
529
529
530
+ it ( 'should set $submitted to true on child forms when parent is submitted' , function ( ) {
531
+ doc = jqLite (
532
+ '<ng-form name="parent">' +
533
+ '<ng-form name="child">' +
534
+ '<input ng:model="modelA" name="inputA">' +
535
+ '<input ng:model="modelB" name="inputB">' +
536
+ '</ng-form>' +
537
+ '</ng-form>' ) ;
538
+ $compile ( doc ) ( scope ) ;
539
+
540
+ var parent = scope . parent ,
541
+ child = scope . child ;
542
+
543
+ parent . $setSubmitted ( ) ;
544
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
545
+ } ) ;
530
546
531
547
it ( 'should deregister a child form when its DOM is removed' , function ( ) {
532
548
doc = jqLite (
You can’t perform that action at this time.
0 commit comments