Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#7739 closed feature (wontfix)

Datepicker: allow maxDate restriction based on number of occurrences

Reported by: tad Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.datepicker Version: 1.8.16
Keywords: Cc:
Blocked by: Blocking:

Description

I'm looking to implement a feature that limits the maximum selectable date not based on a date range, but based on the number of selectable dates (determined via the beforeShowDay callback). This would be extremely useful for user selection of dates within an RFC-2445 or RFC-5545 recurrence rule, wherein the recurrence range may be limited by a COUNT declaration.

For example, to limit the selection to the next 10 selectable dates:

$('#date').datepicker({
    'maxOccurrences': 10
});

Say your beforeShowDay callback returns true on Monday, Wednesday, and Friday of every other week. This option would limit the selection to those days every other week for the next 20 weeks.

Change History (9)

comment:1 Changed 9 years ago by tad

I've created a jsFiddle to describe in more detail what I'm requesting:

http://jsfiddle.net/tadfisher/3aTcS/

This datepicker has a beforeShowDay callback that limits selectable dates to odd dates only. With maxDate set to '+5', the maximum selectable day is 5 days in the future, leaving me with 2 or 3 selectable days. I'm requesting a feature that would limit to 5 selectable instances, which may be more than 5 days in the future, and is really hard/redundant to calculate depending on recurrence rules.

comment:2 Changed 9 years ago by Scott González

Resolution: wontfix
Status: newclosed

This would require the datepicker to fully understand ranges. You should just calculate the actual max date based on the start, frequency and count and pass the proper date.

comment:3 Changed 9 years ago by tad

I disagree. The datepicker does not need to 'fully understand' ranges -- it just needs additional state, such as a counter from some initial date. It most definitely does not need to know what 'third Sunday of every other month' means, nor does it need to know when the range ends.

comment:4 Changed 9 years ago by Scott González

How could it possibly calculate the max date without knowing what "third Sunday of every other month" means? An initial date + a counter is meaningless unless you know what you're counting.

comment:5 Changed 9 years ago by tad

Does it need to know the max date? It really only needs to know if it has seen x valid dates from beforeShowDay. It can know this by using a start date and a counter.

comment:6 Changed 9 years ago by Scott González

That's a really bad implementation, which requires you to know the max date to an extent anyway (you have to at least know the max month).

comment:7 Changed 9 years ago by tad

Why do you have to know the max month? The only reason I can think of is to disable the 'next month' button, which can be done once maxOccurrences is reached.

comment:8 Changed 9 years ago by Scott González

You're assuming that minDate and maxDate are the range start and stop, which is a horrible assumption. What happens when the range is every Monday from 2010 to 2012, but you're using the datpeicker to pick a future date? You need actual knowledge of the range. There is no way you can build a solution that will actually work without that knowledge. The fact that you can create an arbitrary scenario where it does work doesn't mean it's a valid solution.

comment:9 Changed 9 years ago by tad

Fine, then this could be a maxDate option, like '+5o' for 5 occurrences. Now we're being explicit about when we expect the range to end. The first occurrence then becomes the first valid beforeShowDay result after minDate, or the first displayed in or after the default month if no minDate is set. The range ends (we disable the 'next month' button) when the fifth occurrence is displayed.

Or I can just loop over every occurrence myself and set the maxDate. I was just trying to avoid doing this many times, because the datepicker is doing it anyway behind the scenes.

Note: See TracTickets for help on using tickets.