Mat-Stepper -> stepControl problem

4,293 views
Skip to first unread message

lula

unread,
Nov 29, 2017, 8:07:28 AM11/29/17
to angular-material2
Hi.
I use the following stepper: https://material.angular.io/components/stepper/overview
This is an example of my code structure.

<mat-horizontal-stepper [linear]="true">
  <mat-step [stepControl]="firstFormGroup">
   <-- Code for the first step. -->
  </mat-step>

  <mat-step [stepControl]="?????">
      <ng-template matStepLabel>Fill out your address</ng-template>
<form [formGroup]="secondFormGroup_1">
     
      <mat-form-field>
        <input matInput placeholder="Address" formControlName="secondCtrl" required>
      </mat-form-field>
      </form>
      <form [formGroup]="secondFormGroup_2">
      <mat-form-field *ngIf "VARAIBLE = 1">
        <input matInput placeholder="Address" formControlName="secondCtrl2" required>
      </mat-form-field>
      </form>

      <div>
        <button mat-button matStepperPrevious>Back</button>
        <button mat-button matStepperNext>Next</button>
      </div>
   
  </mat-step>

  <mat-step>
   <-- Code for the third Step -->
  </mat-step>
</mat-horizontal-stepper>



I would like to use two FormGroups in Step 2.
The second input field is only visible if any variable = 1.
This also works as intended.
Only the step control does not do what I want.

The following options are possible:

[StepControl] = "secondFormGroup_1" --->
Only secondFormGroup_1 must be valid to continue. This works.
[StepControl] = "secondFormGroup_2" --->
Only secondFormGroup_2 must be valid
to continue. This works.


[StepControl] = "secondFormGroup_1 && secondFormGroup_2 " ---> Only secondFormGroup_2 must be valid to continue. This is wrong.
[StepControl] = "secondFormGroup_2 && secondFormGroup_1 " ---> Only secondFormGroup_1 must be valid to continue. This is wrong.


My goal:
secondFormGroup_1 must always be valid to continue.
In addition, if the variable = 1, the secondFormGroup_2 must be valid to continue.


The following should actually work, but does not work.
[StepControl] = "(secondFormGroup_1 && variable = 0 ) || (secondFormGroup_1 && secondFormGroup_2 && variable= 1)"


Please help me :)

Chen Lit Chian

unread,
Jun 27, 2018, 3:23:13 AM6/27/18
to angular-material2
Hi, Have u found any solution on this??

Dinesh Kannan.C

unread,
Nov 24, 2018, 6:36:21 AM11/24/18
to angular-material2
I am also facing same problem.

Any one or Angular material team please suggest some approach..

Thank You!

Rosa María Bonilla Jiménez

unread,
May 18, 2023, 5:13:45 AM5/18/23
to angular-material2
I am also facing same problem.

Reply all
Reply to author
Forward
0 new messages