Topic: Set date in DatePicker dynamically

akrolis pro asked 6 years ago


Hello,

I have a mdb-date-picker inside a reactive form and I load the date from an external API (i'm using the method described here: https://mdbootstrap.com/support/angular/howto-programmatically-set-the-date-in-datepicker/ adapted from ngModel to a FormGroup).

When I was using v6.3.0 it all worked ok, but since I updated to v7.1.0 the initial date doesn't appear in the datepicker input.

The value it's there because when I click on the datepicker and it opens the correct date is selected and only then also appears in the input (once it's opened it works fine, I can select dates and they appear in the input correctly)

<mdb-date-picker #datePicker mdbDateFormat formControlName="date" [options]="date_options" [placeholder]="" [label]="'Date'"></mdb-date-picker>
.subscribe( data=> { 
this.object = data;
.....
setTimeout(() =>this.datePicker.onUserDateInput(this.object['date']), 0);
//I also tried this (it worked with v.6.3.0 too):
//this.form.controls.date.setValue(this.object['date']);
});


Thanks.


Arkadiusz Idzikowski staff answered 6 years ago


Hello,

What is the value of the data you pass to the 'this.object'? 

We will take a closer look at this. For now please try to pass a string to the setValue method, for example: 

setValue('2018-12-13');
 
Regards,
Arek

akrolis pro commented 6 years ago

Hi, thanks for the answer. I always use setValue as my default method, I only used the one I linked as a backup.

The value of this.object['date'] is a string with the format 'dd/mm/yyyy'. It's the same format I applied to IMyOptions.

Again, the value is correct because when I click on the input the correct date is selected.

Here's a picture of a before/after click using this.form.controls.date.setValue('19/10/2011'): https://imgur.com/eX945jT


Arkadiusz Idzikowski staff commented 6 years ago

Thank you for all the information. We already found the cause of this problem and it will be fixed in next version (next week). I'm afraid there is no quick workaround for this that will work without our fix.


akrolis pro commented 6 years ago

No problem, I'll wait for the fix.

Thanks!



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 7.0.0
  • Device: Desktop / Mobile
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: Yes
  • Provided link: Yes