Skip to content

Commit

Permalink
fix(datepicker): changing the date programatically selects the correc…
Browse files Browse the repository at this point in the history
…t date (#1041)

fixes #858
  • Loading branch information
Martin Cavoj authored and valorkin committed Oct 4, 2016
1 parent b38db2a commit fb6d532
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions components/datepicker/datepicker.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, EventEmitter, Input, Output, Self } from '@angular/core';
import { Component, EventEmitter, Input, Output, Self, ViewChild } from '@angular/core';
import { DatePickerInnerComponent } from './datepicker-inner.component';
import { ControlValueAccessor, NgModel } from '@angular/forms';

/* tslint:disable:component-selector-name component-selector-type */
Expand Down Expand Up @@ -66,6 +67,8 @@ export class DatePickerComponent implements ControlValueAccessor {
private _now:Date = new Date();
private _activeDate:Date;

@ViewChild(DatePickerInnerComponent) private datePicker: DatePickerInnerComponent;

@Input()
public get activeDate():Date {
return this._activeDate || this._now;
Expand All @@ -82,7 +85,6 @@ export class DatePickerComponent implements ControlValueAccessor {
}

public onUpdate(event:any):void {
this.writeValue(event);
this.cd.viewToModelUpdate(event);
}

Expand All @@ -92,19 +94,12 @@ export class DatePickerComponent implements ControlValueAccessor {

// todo: support null value
public writeValue(value:any):void {
// todo: fix something sends here new date all the time
// if (value) {
// if (typeof value !== 'Date') {
// value = new Date(value);
// }
//
// this.activeDate = value;
// }
if (value === this._activeDate) {
if (this.datePicker.compare(value, this._activeDate) === 0) {
return;
}
if (value && value instanceof Date) {
this.activeDate = value;
this.datePicker.select(value);
return;
}

Expand Down

0 comments on commit fb6d532

Please sign in to comment.