Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: dynamically add enableDate to datePicker

herve pro asked 4 years ago


I would like to enable several days in the datePicker component (ie 4 next fridays)

first i disable all dates, then I create an array like this : [{year: 2020, month: 4, day: 10},{year: 2020, month: 4, day: 17},{year: 2020, month: 4, day: 24},{year: 2020, month: 5, day: 1}] and then : this.data.myDatePickerOptions.enableDays = this.tabDays;

this doesn't work, the dates are not enabled

but when i use the following code it works : this.data.myDatePickerOptions.enableDays = [{year: 2020, month: 4, day: 10},{year: 2020, month: 4, day: 17},{year: 2020, month: 4, day: 24},{year: 2020, month: 5, day: 1}];

what is the solution to dynamically add these dates to the enableDays ?

Thank you


Arkadiusz Idzikowski staff answered 4 years ago


Angular can't detect if one of the object parameters changed. It will run change detection only when it detect a change of the object that you pass to options input. That's why in this case you need to clone the options object, for example:

updateEnabledDays() {
  this.myDatepickerOptions.enableDays = this.tabDays;
  this.myDatepickerOptions = { ...this.myDatepickerOptions };
}

herve pro commented 4 years ago

Thank you very much, it works very well !



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.4.0
  • Device: pc
  • Browser: chrome
  • OS: windows 7
  • Provided sample code: No
  • Provided link: No