Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Format of datepicker not being used on render. #69

Closed
nlubin-lv opened this issue Jan 24, 2017 · 2 comments
Closed

Format of datepicker not being used on render. #69

nlubin-lv opened this issue Jan 24, 2017 · 2 comments

Comments

@nlubin-lv
Copy link

nlubin-lv commented Jan 24, 2017

The passed format to the datepicker only is being used when a new date is selected, when it first loads it uses the default format.

    dateFormat = 'MM/DD/YYYY';

Template:

    <md2-datepicker
       [formControlName]="question.key"
       [id]="question.id"
       [type]="question.type"
       [format]="dateFormat"
   ></md2-datepicker>
@nlubin-lv
Copy link
Author

nlubin-lv commented Jan 24, 2017

It seems like writeValue is being called before the format is set from the component so it uses the default.

Right now in my app I am proxying the writeValue for the DatePicker to have the correct format (as a hack) before this gets fixed in the library.


This is my current hack:

const _dateFormat = 'MM/DD/YYYY';
const writeValue = Md2Datepicker.prototype.writeValue;

// need to override this function because the format is set wrong here
Md2Datepicker.prototype.writeValue = function (value): void {
    this.format = _dateFormat;
    writeValue.call(this, value);
};

@nlubin-lv nlubin-lv changed the title Format of datepicker is only used on select Format of datepicker not being used on render. Jan 24, 2017
@yuzhva
Copy link

yuzhva commented Jan 26, 2017

➕1️⃣ I had the issue in my demo project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants