Skip to content

Commit

Permalink
fix(datepicker): added support for null value
Browse files Browse the repository at this point in the history
Introduced support for null as default value:

- In the ngOnInit method of the datepicker-inner class the update should only emit when selectedDate is changed.
- Extra check in compare function
- activeDate() shouldn't return today when not set

fixes #16, closes #445
  • Loading branch information
Johan Smolders authored and valorkin committed Apr 26, 2016
1 parent 75b3568 commit 794347e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 12 additions & 2 deletions components/datepicker/datepicker-inner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ export class DatePickerInner implements OnInit {

if (this.initDate) {
this.activeDate = this.initDate;
this.selectedDate = new Date(this.activeDate.valueOf());
<<<<<<< HEAD
this.update.emit(this.activeDate);
// Only emit if selectedDate changed, otherwise datepicker already has correct value.
=======
// Only emit if selectedDate changed, otherwise datepicker already has correct value.
this.update.emit(this.activeDate);
>>>>>>> 966ba3b... s
} else if (this.activeDate === undefined) {
this.activeDate = new Date();
}
this.selectedDate = new Date(this.activeDate.valueOf());

this.update.emit(this.activeDate);
this.refreshView();
}

Expand All @@ -150,6 +156,10 @@ export class DatePickerInner implements OnInit {
}

public compare(date1:Date, date2:Date):number {
if(date1=== undefined || date2 === undefined) {
return undefined;
}

if (this.datepickerMode === 'day' && this.compareHandlerDay) {
return this.compareHandlerDay(date1, date2);
}
Expand Down
2 changes: 0 additions & 2 deletions components/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export class DatePicker implements ControlValueAccessor {
cd.valueAccessor = this;
}

private _now:Date = new Date();

public set activeDate(value:Date) {
this._activeDate = value;
}
Expand Down

0 comments on commit 794347e

Please sign in to comment.