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 +31
-5
lines changed
Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -274,12 +274,22 @@ FormController.prototype = {
274274 * @name form.FormController#$setSubmitted
275275 *
276276 * @description
277- * Sets the form to its submitted state.
277+ * Sets the form to its `$submitted` state. This will also set `$submitted` on all child and
278+ * parent forms of the form.
278279 */
279- $setSubmitted : function ( ) {
280- this . $$animate . addClass ( this . $$element , SUBMITTED_CLASS ) ;
281- this . $submitted = true ;
282- this . $$parentForm . $setSubmitted ( ) ;
280+ $setSubmitted : function ( onlySetOnChildren ) {
281+ this . $$animate . addClass ( this . $$element , SUBMITTED_CLASS ) ;
282+ this . $submitted = true ;
283+
284+ if ( ! onlySetOnChildren ) {
285+ this . $$parentForm . $setSubmitted ( ) ;
286+ }
287+
288+ forEach ( this . $$controls , function ( control ) {
289+ if ( control . $setSubmitted ) {
290+ control . $setSubmitted ( true ) ;
291+ }
292+ } ) ;
283293 }
284294} ;
285295
Original file line number Diff line number Diff line change @@ -539,6 +539,22 @@ describe('form', function() {
539539 expect ( parent . $submitted ) . toBeTruthy ( ) ;
540540 } ) ;
541541
542+ it ( 'should set $submitted to true on child forms when parent is submitted' , function ( ) {
543+ doc = jqLite (
544+ '<ng-form name="parent">' +
545+ '<ng-form name="child">' +
546+ '<input ng:model="modelA" name="inputA">' +
547+ '<input ng:model="modelB" name="inputB">' +
548+ '</ng-form>' +
549+ '</ng-form>' ) ;
550+ $compile ( doc ) ( scope ) ;
551+
552+ var parent = scope . parent ,
553+ child = scope . child ;
554+
555+ parent . $setSubmitted ( ) ;
556+ expect ( child . $submitted ) . toBeTruthy ( ) ;
557+ } ) ;
542558
543559 it ( 'should deregister a child form when its DOM is removed' , function ( ) {
544560 doc = jqLite (
You can’t perform that action at this time.
0 commit comments