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 8109dd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 6 additions & 2 deletions components/datepicker/datepicker-inner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export class DatePickerInner implements OnInit {

if (this.initDate) {
this.activeDate = this.initDate;
this.selectedDate = new Date(this.activeDate.valueOf());
this.update.emit(this.activeDate);
} 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 +150,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
7 changes: 2 additions & 5 deletions components/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Component, Self, Input} from 'angular2/core';
import {
CORE_DIRECTIVES, FORM_DIRECTIVES, ControlValueAccessor, NgModel
} from 'angular2/common';
import {CORE_DIRECTIVES, FORM_DIRECTIVES, ControlValueAccessor, NgModel} from 'angular2/common';
import {DatePickerInner} from './datepicker-inner';
import {DayPicker} from './daypicker';
import {MonthPicker} from './monthpicker';
Expand Down Expand Up @@ -69,6 +67,7 @@ export class DatePicker implements ControlValueAccessor {
public onTouched:any = Function.prototype;

public cd:NgModel;
private _now:Date = new Date();
private _activeDate:Date;

@Input()
Expand All @@ -82,8 +81,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 8109dd2

Please sign in to comment.