longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

Add Disable dates by array or Optional dates by array #451

Closed chaooo closed 5 years ago

chaooo commented 5 years ago
  1. Add the disable dates by array like this ['2020-01-01', '2020-12-20'];
  2. Add the optional dates by array, the earliest date will be the minimum of the optional dates, the latest date will be the maximum of the optional dates.
holtkamp commented 5 years ago

Hey @chaooo thanks for this clean contribution.

Not sure I understand the optionalDates. Maybe you mean something like possibleDates?

And what happens when a user also has defined a beforeShowDay callback?

I leave it up to our new contributor @monovertex to decide whether we should merge this...

monovertex commented 5 years ago

Hi, I'm AFK this week so I can't comment on the code changes. However, I'd refrain from merging new PRs until we handle the other issues with repository organization and lack of unit tests. I'll get started with this ASAP so it shouldn't be long.

chaooo commented 5 years ago

Thank you for your reply, the optional date means that the date to choose is given by the user in advance. Since I have a usage scenario where the usable date of a product is an array returned by the backend interface, the selectable date must be within the date returned by the backend interface. So I added the option for the optionalDates.

I didn't think about the consequences when a user also has defined a beforeShowDay callback, so this is a bit of a lack of consideration, I hope to consider extending this feature in the future.

monovertex commented 5 years ago

Sorry for the long delay.

Since we already have the beforeShowDay, which can be easily used to achieve this optionalDates/possibleDates functionality, I don't think we should include extra code with the same result. Here's a jsfiddle showing how beforeShowDay can be leveraged. This approach has the advantage that optionalDates can be dynamic. With the proposed changes in the PR you'd have to re-initialize the datepicker or mutate the option array directly.

I'm closing this PR. If you want to continue the discussion and want to present arguments for implementing the specific optionalDates parameter, please reply in this thread.