Click here to Skip to main content
15,881,631 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what is the best way the read input from user when one have a material stepper with lots of different fields?

the is part of the code as it is a little bit huge but just to take an idea:

<mat-horizontal-stepper [linear]="isLinear" #stepper>
  <!--Merchant Resource-->
  <mat-step [stepControl]="merchantResource">
    <form [formGroup]="merchantResource">
      <ng-template matStepLabel>Merchant Resource</ng-template>

      <div class="example-container">


        <table class="merchant-resource-table" cellspacing="0">
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput  id="merchantName" placeholder="Merchant Name" formControlName="merchantResourceCtrl" required>
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput placeholder="Trade Name" formControlName="merchantResourceCtrl" required>
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput type="number" placeholder="Registration Number" formControlName="merchantResourceCtrl"
                  required>
              </mat-form-field>
            </td>


What I have tried:

i dont know if there is a way to group them per step or not , i tried to surf through internet but cannot find anything .. anyhelp please ?
Posted
Updated 13-Feb-19 1:33am

1 solution

The normal way to do this would be to separate each mat-step out into its own formgroup.
HTML
<mat-step [stepControl]="myForm1">
  <form [formGroup]="myForm1">
    <mat-form-field ....
  </form>
</mat-step>
<mat-step [stepControl]="myForm2">
  <form [formGroup]="myForm2">
    <mat-form-field ....
  </form>
</mat-step>
<mat-step [stepControl]="myForm3">
  <form [formGroup]="myForm3">
    <mat-form-field ....
  </form>
</mat-step>
 
Share this answer
 
Comments
Joe Doe234 13-Feb-19 8:07am    
and if every form group have more than one field .. how can i get the data the user inputted ?
Pete O'Hanlon 13-Feb-19 8:29am    
These are just standard form groups. You'd get them in the same way you'd get from a form group if it was a single control with multiple fields. There's nothing special about this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900