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 Aug 20, 2023
1 parent 5f1fb48 commit 3cfdab6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export const CALENDAR_VALUE_ACCESSOR: any = {
</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 @@ -1650,6 +1651,10 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
return true;
}

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

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

0 comments on commit 3cfdab6

Please sign in to comment.