spongessuck / gm.datepickerMultiSelect

AngularJS module to extend UI Bootstrap's Datepicker directive to allow for multiple date selections.
MIT License
73 stars 41 forks source link

Getting datepicker showing pre selected days #27

Closed agriboz closed 9 years ago

agriboz commented 9 years ago

Here is the scenario, I have selectedDays array miliseconds in it. What i want is, showing the datepicker for the correct month.

http://plnkr.co/edit/aiy7kv?p=preview

spongessuck commented 9 years ago

It looks like your selectedDays times in milliseconds aren't corresponding to midnight on the days you want selected- though that may be a timezone issue.

It does initially show December for me, so I'm guessing you're having trouble getting the dates to show as selected.

Check out my fork and let me know if it helps:

http://plnkr.co/edit/sd60xsrl2YDHP9mUGb73?p=preview

brenovieira commented 9 years ago

@agriboz , what you want is set init-date.

And as @spongessuck said, your dates are not correct.

Please use new Date().setHours(0,0,0,0) instead (as described on Usage)

Here is a working fork for your plunker: http://plnkr.co/edit/ZzJvLF?p=preview

agriboz commented 9 years ago

It is working quite well at the moment. Thanks for your quick reply.

By the way, have you ever tried with the new version of angular-bootstrap 0.14.2. It seems activated dates are not working correctly.

http://plnkr.co/edit/ZEE4QZYq7TCLzNdWpTvP?p=preview

brenovieira commented 9 years ago

@agriboz , again, to show the correct month, use init-date instead of activeDate.

This code won't work properly:

var test = new Date(1450735200000).setHours(0,0,0,0);

  //test.setDate(test.getDate()-1);

  //this.activeDate = 1450735200000;
  // TypeError: newVal.getTime is not a function

  this.activeDate = test;
  // it shows the correct month, however, it breaks selectedDays array (removes)

This should be

var test = new Date(1450735200000).setHours(0,0,0,0);

  //test.setDate(test.getDate()-1);

  //this.activeDate = 1450735200000;
  // TypeError: newVal.getTime is not a function

  this.initDate = test;
  // it shows the correct month, however, it breaks selectedDays array (removes)

And add a init-date="app.initDate" in your <datepicker>.

angular-bootstrap 0.14.2 doesn't change datepicker as seen in changelog. So if it works with 0.14.1, it will work with 0.14.2 as well.

spongessuck commented 9 years ago

@agriboz Please try using the newest release of the module (v1.0.6) which was released yesterday. This version will support UI Bootstrap 0.14.