amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.01k forks source link

Disable different weekdays in multiple date ranges #1102

Open ThisIsJustARandomGuy opened 6 years ago

ThisIsJustARandomGuy commented 6 years ago

Hi! I have been looking around for quite some time now, but I can't seem to find an answer. Is it possible to disable different disabled weekdays for different date ranges? I am building a booking form where it's possible to have multiple date ranges where a product will be available on different days. Something like this:

Range1: 01.01.2018 - 31.12.2018: Mon, Tue, Fri Range2: 01.01.2019 - 31.12.2020: Wed, Fri, Sun Range3: 01.01.2020 - 05.02.2020: Sat

I know that it's possible to calculate an array of all available/disabled days, but that would be quite the long list and I'm not sure about performance implications (there may be ten date pickers on the page). The available ranges can be anywhere from a few days to a few months with most products having around three to five ranges.

Unfortunately I can't really post working code, since the picker is wrapped in a React component and calculates the available dates. It's a default picker though, nothing fancy. Any help would be appreciated!

DanielRuf commented 6 years ago

Sure, the disable setting can do that, but in general for the whole range.

http://amsul.ca/pickadate.js/date/#disable-dates-all shows a way to define different ranges. Also you could probably write a method which returns the needed values using the Date object of JavaScript.

http://amsul.ca/pickadate.js/date/#disable-dates-use-integers

In general I would recommend generating this from your backend if the different disable options are not sufficient.