ng-lightning / ng-lightning

Native Angular components & directives for Lightning Design System

Home Page:http://ng-lightning.github.io/ng-lightning/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Datepicker-input : validation error when date initialized by ControlForm

QuentinLemCode opened this issue · comments

Hello,

I'm using Ngl-Datepicker-input for a Date input.
I want to use it with a FormControl with a pre-filled date.

So here is the HTML :

<ngl-datepicker-input format="little-endian" [formControl]="dateTarifControl" label="Date tarif" [class.slds-has-error]="dateTarifControl.invalid"></ngl-datepicker-input>

and the Typescript :

const date = new Date(2019, 5, 21); // just for example
this.dateEffetControl = new FormControl(moment(date).format('DD/MM/YYYY'),[Validators.required]);

The component mark the input invalid with this error :
image

Is there a way to init the ngl-datepicker-input with a pre-filled date, using it with reactive form ?
Thanks

@Worlor The datepicker works with Date objects, not strings. So you have to do:
this.dateEffetControl = new FormControl(new Date(2019, 5, 21), [Validators.required]);

Thanks for reply, I have tried this, but the problem was elsewhere.
The bug was coming from the object returned from my service (a date attribute that was, in fact, a string...)