Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Applied fix for selectOtherMonths option as it wasnt working properly.
Correct CSS class now applied for dates from other months depending on the value of selectOtherMonths option.
Year calculated properly for date in the next month (but the same year). primefaces#1935
Selectable property set on the date from other month properly based on the value of selectOtherMonths option.
  • Loading branch information
external-olgierd authored Feb 27, 2017
1 parent a97a4c3 commit 467d68d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions components/calendar/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgModule,Component,ElementRef,AfterViewInit,OnDestroy,OnInit,Input,Output,SimpleChange,EventEmitter,forwardRef,Renderer,trigger,state,style,transition,animate,ViewChild,ChangeDetectorRef} from '@angular/core';
import {NgModule,Component,ElementRef,AfterViewInit,OnDestroy,OnInit,Input,Output,SimpleChange,EventEmitter,forwardRef,Renderer,trigger,state,style,transition,animate,ViewChild} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ButtonModule} from '../button/button';
import {InputTextModule} from '../inputtext/inputtext';
Expand Down Expand Up @@ -68,7 +68,7 @@ export interface LocaleSettings {
</thead>
<tbody>
<tr *ngFor="let week of dates">
<td *ngFor="let date of week" [ngClass]="{'ui-datepicker-other-month ui-state-disabled':date.otherMonth,
<td *ngFor="let date of week" [ngClass]="{'ui-datepicker-other-month ui-state-disabled':date.otherMonth && !selectOtherMonths,
'ui-datepicker-current-day':isSelected(date),'ui-datepicker-today':date.today}">
<a class="ui-state-default" href="#" *ngIf="date.otherMonth ? showOtherMonths : true"
[ngClass]="{'ui-state-active':isSelected(date), 'ui-state-highlight':date.today,'ui-state-disabled':!date.selectable}"
Expand Down Expand Up @@ -304,7 +304,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
this.createMonth(this.currentMonth, this.currentYear);
}

constructor(public el: ElementRef, public domHandler: DomHandler,public renderer: Renderer, private cd: ChangeDetectorRef) {}
constructor(public el: ElementRef, public domHandler: DomHandler,public renderer: Renderer) {}

ngOnInit() {
let date = this.defaultDate||new Date();
Expand Down Expand Up @@ -379,7 +379,8 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
for(let j = (prevMonthDaysLength - firstDay + 1); j <= prevMonthDaysLength; j++) {
let prev = this.getPreviousMonthAndYear(month, year);
week.push({day: j, month: prev.month, year: prev.year, otherMonth: true,
today: this.isToday(today, j, prev.month, prev.year), selectable: this.isSelectable(j, prev.month, prev.year)});
today: this.isToday(today, j, prev.month, prev.year),
selectable: this.selectOtherMonths && this.isSelectable(j, prev.month, prev.year)});
}

let remainingDaysLength = 7 - week.length;
Expand All @@ -395,7 +396,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
let next = this.getNextMonthAndYear(month, year);
week.push({day: dayNo - daysLength, month: next.month, year: next.year, otherMonth:true,
today: this.isToday(today, dayNo - daysLength, next.month, next.year),
selectable: this.isSelectable((dayNo - daysLength), next.month, next.year)});
selectable: this.selectOtherMonths && this.isSelectable((dayNo - daysLength), next.month, next.year)});
}
else {
week.push({day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year),
Expand Down Expand Up @@ -559,6 +560,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
}
else {
m = month + 1;
y = year;
}

return {'month':m,'year':y};
Expand Down Expand Up @@ -1166,7 +1168,6 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce

this.closeOverlay = true;
this.dateClick = false;
this.cd.detectChanges();
});
}
}
Expand Down

0 comments on commit 467d68d

Please sign in to comment.