react-dates icon indicating copy to clipboard operation
react-dates copied to clipboard

Can select a range with blocked dates using the DateRangePicker

Open majapw opened this issue 9 years ago • 31 comments

This should maybe be an option instead of the default. We're going to eventually need to prevent people from selecting date ranges that include blocked dates.

majapw avatar Aug 19 '16 00:08 majapw

@majapw can you please specify the exact behaviour that is expected, as in when the user tries to click on end date with block dates included in duration should the user click be disabled or is he allowed to click but the date range is not selected with an error saying blocked dates in range ?

agupta93 avatar Sep 12 '16 09:09 agupta93

I think no error message for now (we're working on a possible design for that sort of scenario). Most importantly, if there is a hover span, that should disappear once the span itself contains a blocked date (similar to what happens when you hover over a blocked date itself).

As for the click, the click should register up through to the DateRangePicker component, but should be prevented from doing anything further in that component's handleDayClick method I think.

My biggest problem with this when I tried to implement this previously was performance. Namely I got a solution that worked rather well for short ranges, but slowed the entire component down hella when the range was a handful of months.

majapw avatar Sep 12 '16 15:09 majapw

@majapw okay i kinda understood it will start working on this one now :) will ask if i encounter further doubts

agupta93 avatar Sep 15 '16 20:09 agupta93

@majapw i have tried implementing this feature and as you said there were performance issues as the range increased to months and years. This majorly stems from the fact that you have to iterate though days again and again. I have tried implementing in a way to avoid such iteration and have reached to the following behaviour screenshot is attached

image

As it can be seen in the image that if blocked dates are not allowed the span only extends before the first blocked date and disappears on any date after the blocked that indicating that the user can only select the range without blocked dates. Tell me if this behaviour is ok so that i can proceed with it further

agupta93 avatar Oct 02 '16 08:10 agupta93

Any update?

gigitux avatar Jan 26 '17 16:01 gigitux

Looks great @agupta93 This is exactly the behaviour that we are looking for. Do you have the work you've done so far on a branch/fork that I might be able to checkout?

oldo avatar Feb 08 '17 12:02 oldo

@oldo yes i might have the branch but as u can see it was done months ago, since i received no confirmation i stopped working on it. Its still a work in progress tell me when you need it and will try to complete and give you the branch :)

agupta93 avatar Feb 08 '17 17:02 agupta93

Ready when you are @agupta93 :-) I'm about to start working on implementing this feature now so even if you are not 100% happy with what you've done please feel free to share it as it would be a great headstart. Thanks!

oldo avatar Feb 08 '17 20:02 oldo

@oldo okay will give u the branch this weekend busy in some lately i hope u can wait :)

agupta93 avatar Feb 09 '17 21:02 agupta93

@agupta93 thank you! I look forward to having a look :-)

oldo avatar Feb 09 '17 23:02 oldo

@oldo https://github.com/agupta93/react-dates/tree/blocked-dates here is the branch my changes are in the commit tempCommit have a look

agupta93 avatar Feb 16 '17 18:02 agupta93

Are there any updates to this?

vongkim avatar Apr 13 '17 07:04 vongkim

@agupta93 apologies for the delayed response. Thanks very much for sharing your work. In the end I resolved the problem by creating a function that checks for blocked dates between a start and end date:

export function checkForBlockedDates(start, end, dates) {
  const dateFormat = 'YYYY-MM-DD';
  const diff = moment(end).diff(start, 'days') + 1;

  for (let i = 0; i < diff; i++) {
    const checkDate = moment(start).add(i, 'd').format(dateFormat);

    if (dates[checkDate] && dates[checkDate].blocked) {
      return true;
    }
  }

  return false;
}

And if this function returns true then I just clear selection and display a modal saying that there are blocked dates within the selected range.

oldo avatar Apr 13 '17 23:04 oldo

my $0.02: After the user selects the first date, disable all dates after the first blocked date following the selected date. A different background color could be used to differentiate these dates from the blocked dates.

ingoclaro avatar Jun 06 '17 02:06 ingoclaro

@ingoclaro agreed, that's how we're doing it on our end. But there are some undesirable edge cases, because if there is no initial value, the initial check for blocked dates after start date is selected happens before startDate is passed to the change handler.

@majapw is there still desire for a PR on this? Thanks!

timhwang21 avatar Jun 15 '17 20:06 timhwang21

@agupta93 would be really helpful if this feature would be included as an option into the master branch - any plans for that?

laurenz-glueck avatar Aug 31 '17 07:08 laurenz-glueck

My $.02 - think there should be a clear difference between blocked functionally and blocked visually. Perhaps 2 props - isDayBlocked vs isDayDisabled? With isDayDisabled not preventing a range selection with a disabled day in the middle.

Use case: bookings at businesses/schools where one needs to disable weekends/holidays but still need to select date-ranges over them.

colemerrick avatar Sep 11 '18 20:09 colemerrick

This is also a featured I'd love to see.

janeschindler avatar Nov 19 '18 21:11 janeschindler

I think that this is a very important and basic feature to implement.

heleneshaikh avatar Jan 08 '19 09:01 heleneshaikh

This would be a great feature to have

skevlishvili avatar Jan 12 '19 20:01 skevlishvili

As a workaround I'm comparing the startDate to the next earliest blocked date, and passing these dates to isOutsideRange.

Would love to have this as a feature!

givi-phirtskhalava avatar Jan 12 '19 20:01 givi-phirtskhalava

Any updates here? 3 years went by since pull request.

lianju avatar Aug 19 '19 14:08 lianju

@majapw How do you handle this at airbnb? Seems that it’s not possible to select a range with blocked dates.

lianju avatar Sep 11 '19 14:09 lianju

Any updates on this? Could really use this functionality.

IadityaM avatar May 04 '20 16:05 IadityaM

Hi, any updates? Is this a part of the main branch yet? It still allows the user to select a range containing some blocked date.

@oldo Thanks for the function you described above. How can I use that? Where should it be called? A simple example would be of immense help. Thanks. 😁

omeiirr avatar Jun 19 '21 15:06 omeiirr

Ufff, sorry @omeiirr, I posted over 4 years ago! Haven't used this library in a while but from memory it was just called when end date is set. Sorry I'm not much more help :-)

oldo avatar Jun 21 '21 11:06 oldo

Has this been resolved? This feels like a pretty important option to have.

ryanwoconnor avatar Dec 06 '21 10:12 ryanwoconnor

Are you looking for a PR to do this?

multiwebinc avatar Jan 07 '22 19:01 multiwebinc

@multiwebinc yep, that’s what the “pull request wanted” label means.

ljharb avatar Jan 08 '22 16:01 ljharb

I think the end is soon for this lib, as there's only 1 sole maintainer for this lib.

danishfareed avatar May 19 '22 05:05 danishfareed