mezoistvan / ng2-flatpickr

Angular 2+ wrapper for flatpickr (https://github.com/chmln/flatpickr)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting an initial value with a formgroup yields no result

enko opened this issue · comments

commented

I'm creating a FormGroup with a field birthday and want to hook it up with a ng2-flatpickr component. If I select a date the formgroup now has the correct value. If I try to set an initial value with this.form.patchValue({ birthday: new Date() }); the flatpickr is empty. I would expect that the flatpickr shows the current date.

Here is my repro-repo: https://github.com/enko/ng2-flatpickr-problem

Relevant files are https://github.com/enko/ng2-flatpickr-problem/blob/master/src/app/app.component.ts and https://github.com/enko/ng2-flatpickr-problem/blob/master/src/app/app.component.html

I just meet the same problem!!!

@mezoistvan If you need help with this issue, then you can assign it to me. I am here to help...

I had this issue, here is what I did to resolve it:

I attach it to an input like this:

<input formControlName="datePickerDate"
       [flatpickr]="datePickerOptions"
       name="datePickerDate">

Then in the component ngOnInit:

this.datePickerOptions = nothingSpecial;
// this is the important part
// initialize the date here
this.datePickerOptions.defaultDate = new Date();

For some reason adding the default date after creating the object made it work for me. ¯\(ツ)
I don't know if it helps anyone else but I hope it does!

@AbuzerAsif If you can fix it, would love to see this issue fixed! Ran into this issue today and couldn't generate a proper fix to it (making reactive form patchValue work as intended) in the time budgeted for our project task. So this is still a current/relevant bug.

@dockleryxk

Thank you. its working.