Skip to main content

Search and Top Navigation

#7739 closed feature (wontfix)

Opened September 26, 2011 07:14PM UTC

Closed September 26, 2011 08:32PM UTC

Last modified September 27, 2011 10:12PM UTC

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.

Attachments (0)
Change History (9)

Changed September 26, 2011 07:24PM UTC by tad comment:1

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.

Changed September 26, 2011 08:32PM UTC by scottgonzalez comment:2

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.

Changed September 26, 2011 09:51PM UTC by tad comment:3

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.

Changed September 27, 2011 01:11AM UTC by scottgonzalez comment:4

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.

Changed September 27, 2011 04:17PM UTC by tad comment:5

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.

Changed September 27, 2011 04:59PM UTC by scottgonzalez comment:6

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).

Changed September 27, 2011 05:01PM UTC by tad comment:7

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.

Changed September 27, 2011 05:09PM UTC by scottgonzalez comment:8

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.

Changed September 27, 2011 10:12PM UTC by tad comment:9

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.