mydea / PikadayResponsive

A responsive datepicker built on top of Pikaday. It shows the native datepicker on mobile devices and a nice JS-picker on desktop.
https://mydea.github.io/PikadayResponsive/
MIT License
166 stars 25 forks source link

Function to set minDate #23

Closed Walkeezy closed 6 years ago

Walkeezy commented 6 years ago

Hi!

Is there a way to set a new minDate, similar to the setDate() function?

In my example I'm taking the value from one Pikaday-instance to set it as the selected date on another instance:

onOpen: function() {
   const arrival_value = arrivalDate.value;
   const default_departure = moment(arrival_value, 'DD. MMMM YYYY').add(1,'days').toDate();
   departureDate.setDate(default_departure);
},

It would be nice to set the value from the first instance as minDate for the second instance.

Thanks!

Gerain2k commented 6 years ago

Hmm minDate is set only for pickadayProperties. My question would be can you access any pickaday Object properties when you use pickadayResponsive.

mydea commented 6 years ago

You can always update the pikaday instance, see: https://github.com/dbushell/Pikaday/issues/19, like this: instance.pikaday.config(...) (Note that minDate takes a native JS date, not a moment date, so you'll need to do e.g. .confg({ minDate: myDate.toDate })). However, this will only work if Pikaday is used, not in native mode. If someone implements https://github.com/mydea/PikadayResponsive/issues/24, we could also add a min/max property to the main config, and add corresponding methods to update them as well.

Walkeezy commented 6 years ago

Thanks man, got it working like this:

onSelect: function() {
   const arrival_value = arrivalDate.value;
   const default_departure = moment(arrival_value, 'DD. MMMM YYYY').add(1,'days').toDate();
   departureDate.pikaday.config({minDate: default_departure});
},