Skip to content

Commit

Permalink
In primeng calendar, date can be lined through or disabled using date…
Browse files Browse the repository at this point in the history
… template. But in year view there is no option to disable dates.

In my solution, if maxDate or minDate is there, then the years outside this range shoud be disabled.
  • Loading branch information
Faisal ahmed committed Nov 9, 2022
1 parent 8d3edd2 commit 82f5125
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export type CalendarTypeView = 'date' | 'month' | 'year';
</span>
</div>
<div class="p-yearpicker" *ngIf="currentView === 'year'">
<span *ngFor="let y of yearPickerValues()" (click)="onYearSelect($event, y)" (keydown)="onYearCellKeydown($event, y)" class="p-yearpicker-year" [ngClass]="{ 'p-highlight': isYearSelected(y) }" pRipple>
<span *ngFor="let y of yearPickerValues()" (click)="onYearSelect($event, y)" (keydown)="onYearCellKeydown($event, y)" class="p-yearpicker-year" [ngClass]="{ 'p-highlight': isYearSelected(y), 'p-disabled': isYearDisabled(y) }" pRipple>
{{ y }}
</span>
</div>
Expand Down Expand Up @@ -1353,6 +1353,10 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
return !this.isSelectable(1, month, this.currentYear, false);
}

isYearDisabled(year) {
return !this.isSelectable(1, this.currentMonth, year, false);
}

isYearSelected(year) {
if (this.isComparable()) {
let value = this.isRangeSelection() ? this.value[0] : this.value;
Expand Down

0 comments on commit 82f5125

Please sign in to comment.