How do I change to required input using Angular Material?

Asked

Viewed 271 times

-1

How can I set as mandatory fields to fill after set choice in the radio as fixed:

inserir a descrição da imagem aqui

Code

html

 <span>
        <label>Atividade Fixa:  </label>
        <mat-radio-group  name="atividade_fixa">
            <mat-radio-button value="true">Sim</mat-radio-button>
            <mat-radio-button value="false">Não</mat-radio-button>
        </mat-radio-group>
    </span>

and

<span>
    <mat-form-field style="width:100px;">
    <input matInput [matDatepickerFilter]="myFilter" [matDatepicker]="dpDataLimite" [min]="data?data:minDate" placeholder="Data Limite" [(ngModel)]="dataLimite"                             name="dpDataLimite">
        <mat-datepicker-toggle matSuffix [for]="dpDataLimite">
    </mat-datepicker-toggle>
        <mat-datepicker #dpDataLimite></mat-datepicker>
     </mat-form-field>
    </span>
  • 1

    It should have a nicer shape, but this is the one I can think of now: https://stackblitz.com/edit/angular-drac5s?file=app%2Fdatepicker-Overview-example.html

1 answer

0


Proposed solution:

<span>
        <label>Atividade Fixa:  </label>
        <mat-radio-group  name="atividade_fixa">
            <mat-radio-button (change)="requiredTime=true" value="true">Sim</mat-radio-button>
            <mat-radio-button (change)="requiredTime=false" value="false">Não</mat-radio-button>
        </mat-radio-group>
</span>
<br>
<mat-form-field>
  <input matInput #inpicker [matDatepicker]="picker" placeholder="Choose a date" [required]="requiredTime">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

Description of the solution:

I added (change) to the radio button so that when selected will set a value to My proposal is to make this input required.

  • 1

    Put an explanation of what you did, to help the next person who is in the same trouble as yours :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.