@@ -557,6 +557,73 @@ describe('form', function() {
557
557
expect ( child . $submitted ) . toBeTruthy ( ) ;
558
558
} ) ;
559
559
560
+
561
+ it ( 'should not propagate $submitted state on removed child forms when parent is submitted' , function ( ) {
562
+ doc = jqLite (
563
+ '<ng-form name="parent">' +
564
+ '<ng-form name="child">' +
565
+ '<ng-form name="grandchild">' +
566
+ '<input ng:model="modelA" name="inputA">' +
567
+ '</ng-form>' +
568
+ '</ng-form>' +
569
+ '</ng-form>' ) ;
570
+ $compile ( doc ) ( scope ) ;
571
+
572
+ var parent = scope . parent ,
573
+ child = scope . child ,
574
+ grandchild = scope . grandchild ,
575
+ ggchild = scope . greatgrandchild ;
576
+
577
+ parent . $removeControl ( child ) ;
578
+
579
+ parent . $setSubmitted ( ) ;
580
+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
581
+ expect ( child . $submitted ) . not . toBeTruthy ( ) ;
582
+ expect ( grandchild . $submitted ) . not . toBeTruthy ( ) ;
583
+
584
+ parent . $addControl ( child ) ;
585
+
586
+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
587
+ expect ( child . $submitted ) . not . toBeTruthy ( ) ;
588
+ expect ( grandchild . $submitted ) . not . toBeTruthy ( ) ;
589
+
590
+ parent . $setSubmitted ( ) ;
591
+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
592
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
593
+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
594
+
595
+ parent . $removeControl ( child ) ;
596
+
597
+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
598
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
599
+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
600
+
601
+ parent . $setPristine ( ) ; // sets $submitted to false
602
+ expect ( parent . $submitted ) . not . toBeTruthy ( ) ;
603
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
604
+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
605
+
606
+ grandchild . $setPristine ( ) ;
607
+ expect ( grandchild . $submitted ) . not . toBeTruthy ( ) ;
608
+
609
+ child . $setSubmitted ( ) ;
610
+ expect ( parent . $submitted ) . not . toBeTruthy ( ) ;
611
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
612
+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
613
+
614
+ child . $setPristine ( ) ;
615
+ expect ( parent . $submitted ) . not . toBeTruthy ( ) ;
616
+ expect ( child . $submitted ) . not . toBeTruthy ( ) ;
617
+ expect ( grandchild . $submitted ) . not . toBeTruthy ( ) ;
618
+
619
+ // Test upwards submission setting
620
+ grandchild . $setSubmitted ( ) ;
621
+ expect ( parent . $submitted ) . not . toBeTruthy ( ) ;
622
+ expect ( child . $submitted ) . toBeTruthy ( ) ;
623
+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
624
+ } ) ;
625
+
626
+
560
627
it ( 'should set $submitted to true on child and parent forms when form is submitted' , function ( ) {
561
628
doc = jqLite (
562
629
'<ng-form name="parent">' +
0 commit comments