Skip to content

Commit

Permalink
feat(datepicker): use init value for the first initialization (#2897)
Browse files Browse the repository at this point in the history
* Add-Init-Config for DateRangePicker for the first initialization of the international date display.

* feat(datepicker): add setConfig in OnInit
  • Loading branch information
BGXi authored and valorkin committed Nov 22, 2017
1 parent 0d72cd6 commit 7ec97f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
20 changes: 14 additions & 6 deletions src/datepicker/bs-datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class BsDatepickerComponent implements OnInit, OnDestroy, OnChanges {
triggers: this.triggers,
show: () => this.show()
});
this.setConfig();
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down Expand Up @@ -149,12 +150,7 @@ export class BsDatepickerComponent implements OnInit, OnDestroy, OnChanges {
return;
}

this._config = Object.assign({}, this._config, this.bsConfig, {
value: this._bsValue,
isDisabled: this.isDisabled,
minDate: this.minDate || this._config.minDate,
maxDate: this.maxDate || this._config.maxDate
});
this.setConfig();

this._datepickerRef = this._datepicker
.provide({provide: BsDatepickerConfig, useValue: this._config})
Expand Down Expand Up @@ -204,6 +200,18 @@ export class BsDatepickerComponent implements OnInit, OnDestroy, OnChanges {
this.show();
}

/**
* Set config for datepicker
*/
setConfig(): void {
this._config = Object.assign({}, this._config, this.bsConfig, {
value: this._bsValue,
isDisabled: this.isDisabled,
minDate: this.minDate || this._config.minDate,
maxDate: this.maxDate || this._config.maxDate
});
}

ngOnDestroy(): any {
this._datepicker.dispose();
}
Expand Down
32 changes: 20 additions & 12 deletions src/datepicker/bs-daterangepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class BsDaterangepickerComponent
triggers: this.triggers,
show: () => this.show()
});
this.setConfig();
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down Expand Up @@ -148,18 +149,7 @@ export class BsDaterangepickerComponent
return;
}

this._config = Object.assign(
{},
this._config,
{displayMonths: 2},
this.bsConfig,
{
value: this._bsValue,
isDisabled: this.isDisabled,
minDate: this.minDate || this._config.minDate,
maxDate: this.maxDate || this._config.maxDate
}
);
this.setConfig();

this._datepickerRef = this._datepicker
.provide({provide: BsDatepickerConfig, useValue: this._config})
Expand All @@ -186,6 +176,24 @@ export class BsDaterangepickerComponent
);
}

/**
* Set config for daterangepicker
*/
setConfig() {
this._config = Object.assign(
{},
this._config,
{displayMonths: 2},
this.bsConfig,
{
value: this._bsValue,
isDisabled: this.isDisabled,
minDate: this.minDate || this._config.minDate,
maxDate: this.maxDate || this._config.maxDate
}
);
}

/**
* Closes an element’s datepicker. This is considered a “manual” triggering of
* the datepicker.
Expand Down

0 comments on commit 7ec97f8

Please sign in to comment.