How to limit PrimeNG Calendar Navigator to the set yearRange?

Viewed 664

I've set p-calendar to a specific yearRange, and use minDate to disable days outside my range. I'm using the yearNavigator and monthNavigator options. I'd like to know how I might prevent the yearNavigator select list from moving before or beyond my set range.

For instance, while my yearRange is set to 2019:2021 and dates before Jan 1, 2019 are disabled, a user can still navigate to January 2019 and click the prev arrow button to get to December 2018. The yearNavigator dropdown is then updated to show 2018:2020. A user cannot select a disabled date, but I'd prefer to not show months in years that have no valid dates.

I can possibly use the onMonthChange event to check the date and disable/hide the prev arrow, but I'm wondering if there's a simpler way to prevent the yearNavigator from changing to a year outside the preset range?

<p-calendar
  formControlName="endDate"
  [required]="true"
  [minDate]="minDate"
  [monthNavigator]="true"
  [yearNavigator]="true"
  [yearRange]="2019:2021"
  [readonlyInput]="true"
  [showIcon]="true"
></p-calendar>
0 Answers
Related