kekeh / angular-mydatepicker

Angular datepicker and date range picker :date:
https://kekeh.github.io/angular-mydatepicker/
MIT License
1 stars 11 forks source link

Unable to set values on inline calendar #10

Closed ghoyle closed 5 years ago

ghoyle commented 5 years ago

Hi, I've bound a date range to the input and want to show the calendar inline, but whenever updating the values via external buttons it wont show on the calendar. Ive tried showing not inline and closing and opening the popup shows the update. Is there any way to update inline?

Screenshot 2019-07-10 at 15 23 58

kekeh commented 5 years ago

Hi @ghoyle

Did you try to change value of options dynamically?

You have to make a copy of options and then change the value.

Here is an example: https://github.com/kekeh/angular-mydatepicker/wiki/options-attribute

kekeh commented 5 years ago

Example on how to set disableSince option dynamically: https://github.com/kekeh/angular-mydatepicker/wiki/disable-since-tomorrow

ghoyle commented 5 years ago

Its the values of the calendar that i want to update. Changing the options shows the range on the initial load, but when using the buttons, the calendar obviously flicks between popup and inline but the range on the calendar doesnt update.

kekeh commented 5 years ago

When you click the button you want to set visible range to calendar. When you click another button you want to set another visible range to calendar. Right?

Can you share the code what you did in the button click function?

ghoyle commented 5 years ago

See below: public setRange = fromDate => { this.dateRange = { isRange: true, singleDate: null, dateRange: { beginEpoc: fromDate.getTime() / 1000, beginDate: { day: fromDate.getDay(), month: fromDate.getMonth(), year: fromDate.getFullYear() }, beginJsDate: fromDate, endEpoc: this.todaysDate.getTime() / 1000, endDate: { day: this.todaysDate.getDay(), month: this.todaysDate.getMonth(), year: this.todaysDate.getFullYear() }, endJsDate: this.todaysDate } }; };

kekeh commented 5 years ago

It doesn't work now because there is a bug. I will fix it tomorrow and inform you. Thanks :-)

kekeh commented 5 years ago

Hi @ghoyle

I fixed this issue. Please install version 0.1.4.

You can set value this way.

<input angular-mydatepicker class="datePicker" type="hidden" 
    [(ngModel)]="model" [options]="myDatePickerOptions"/>
  public model: IMyDateModel = null;

  // set range today + 3 days
  onTodayPlus3(): void {
    let today: Date = new Date();
    let date: Date = new Date();
    date.setDate(date.getDate() + 3);

    this.model = {isRange: true, singleDate: null, dateRange: {
      beginDate: {year: today.getFullYear(), month: today.getMonth() + 1, day: today.getDate()},
      endDate: {year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate()}
    }}; 
  }
ghoyle commented 5 years ago

Sorry for the late reply, Ive been on holiday. Many thanks for the fix!