DOB Datepicker should disable the years based on the value selected in the dropdown field.
- I have a dropdown with 3 values - ADULT, INFANT and CHILD.
- There is another field called DOB which opens a datepicker.
When I select ADULT from the dropdown,in the DOB datepicker, it should enable only from last 100 years to today. It should disable the other years. (Should be able to select from 29 March 1921 to 29 March 2021(today))
Similary, when I select CHILD from the dropdown,in the DOB datepicker, it should enable only from last 12 years to today. It should disable the other years.
For INFANT, last 2 years.
HTML Component Code
<div class="form-group col-md-3" [ngClass]="displayFieldCss('paxType',passengerFormIndex)" *ngIf = "getControlCheckInfo('paxType')">
<label>{{'Pax Type' | translate}}<span *ngIf = "getControlCheckInfo('paxType', true)" class="mandatory-fields err-msg">*</span></label>
<select class="form-control" formControlName="paxType">
<option [ngValue]="null">Select Pax Type</option>
<option *ngFor="let data of paxData" [ngValue]="data">{{data.passengerTypeName}}</option>
</select>
<app-field-error-display [displayError]="isFieldValid('paxType',passengerFormIndex)" errorMsg="Please enter the pax type">
</app-field-error-display>
</div>
<div class="form-group col-md-3" [ngClass]="displayFieldCss('dateOfBirth',passengerFormIndex)" *ngIf = "getControlCheckInfo('dateOfBirth')">
<label>{{'Date of Birth' | translate}}<span *ngIf = "getControlCheckInfo('dateOfBirth', true)" class="mandatory-fields err-msg">*</span></label>
<input [min]="mindateOfBirth" matInput [matDatepicker]="dob" placeholder="Date of Birth" class="form-control"
formControlName="dateOfBirth" (click)="dob.open()">
<mat-datepicker #dob></mat-datepicker>
<app-field-error-display [displayError]="isFieldValid('dateOfBirth',passengerFormIndex)" errorMsg="Please enter the Date Of Birth">
</app-field-error-display>
</div>
I have the respective functions in ts file.