I am looking to implement a feature where the user cannot select or edit the start date for the first two months after the initial start date. If any month is selected other than those two, then I want to calculate the date with an additional 2 months added.
https://i.sstatic.net/ZT98D.png
I also want to restrict the user from selecting the immediate 2 months following the start month.
https://i.sstatic.net/Rv91n.png
If September is selected, I would like to calculate the start date up to the selected date.
https://i.sstatic.net/7zOrJ.png
In the component.ts file:
@Component({
selector: 'app-tax-time-period',
templateUrl: './tax-time-period.component.html',
styleUrls: ['./tax-time-period.component.scss'],
})
export class TaxTimePeriodComponent implements OnInit {
endDateDisable = true;
defaultPickerValue: Date | null = null;
@ViewChild('endDatePicker') endDatePicker!: NzDatePickerComponent;
startDate!: Date;
disabledEndDate = (endDate: Date): boolean => {
if (!endDate || !this.startDate) {
return false;
}
return endDate.getTime() < this.startDate.getTime() ;
}
}
The HTML code:
<nz-form-item>
<nz-form-label>Start Date</nz-form-label>
<nz-form-control>
{{ startDate ? (startDate | date: "YYYY-MM-dd") : "N/A" }}
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired> End Date</nz-form-label>
<nz-form-control
[nzSpan]="5"
nzHasFeedback
[nzErrorTip]="endDateErrorTpl"
>
<nz-month-picker
#endDatePicker
[nzDisabledDate]="disabledEndDate"
nzFormat="yyyy-MM-dd"
formControlName="endDate"
nzPlaceHolder="End"
(nzOnOpenChange)="handleEndOpenChange($event)"
nzMode="month"
[nzDisabled]="endDateDisable"
[nzDefaultPickerValue]="defaultPickerValue"
></nz-month-picker>