This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ FormController.prototype = {
286286 }
287287
288288 forEach ( this . $$controls , function ( control ) {
289- if ( control . $setSubmitted ) {
289+ if ( control . $setSubmitted && ! control . $submitted ) {
290290 control . $setSubmitted ( true ) ;
291291 }
292292 } ) ;
Original file line number Diff line number Diff line change @@ -553,9 +553,41 @@ describe('form', function() {
553553 child = scope . child ;
554554
555555 parent . $setSubmitted ( ) ;
556+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
556557 expect ( child . $submitted ) . toBeTruthy ( ) ;
557558 } ) ;
558559
560+ it ( 'should set $submitted to true on child and parent forms when form is submitted' , function ( ) {
561+ doc = jqLite (
562+ '<ng-form name="parent">' +
563+ '<ng-form name="child">' +
564+ '<ng-form name="grandchild">' +
565+ '<input ng:model="modelA" name="inputA">' +
566+ '<input ng:model="modelB" name="inputB">' +
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+
576+ spyOn ( parent , '$setSubmitted' ) . and . callThrough ( ) ;
577+ spyOn ( child , '$setSubmitted' ) . and . callThrough ( ) ;
578+ spyOn ( grandchild , '$setSubmitted' ) . and . callThrough ( ) ;
579+
580+ child . $setSubmitted ( ) ;
581+
582+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
583+ expect ( child . $submitted ) . toBeTruthy ( ) ;
584+ expect ( grandchild . $submitted ) . toBeTruthy ( ) ;
585+
586+ expect ( parent . $setSubmitted ) . toHaveBeenCalledOnce ( ) ;
587+ expect ( child . $setSubmitted ) . toHaveBeenCalledOnce ( ) ;
588+ expect ( grandchild . $setSubmitted ) . toHaveBeenCalledOnce ( ) ;
589+ } ) ;
590+
559591 it ( 'should deregister a child form when its DOM is removed' , function ( ) {
560592 doc = jqLite (
561593 '<form name="parent">' +
You can’t perform that action at this time.
0 commit comments