Skip to main content

Search and Top Navigation

#8953 closed bug (patcheswelcome)

Opened January 09, 2013 10:16AM UTC

Closed January 09, 2013 07:02PM UTC

Last modified January 14, 2013 04:51PM UTC

Datepicker: beforeShowDay repeats dates

Reported by: Joel Owned by: Joel
Priority: minor Milestone: 1.11.0
Component: ui.datepicker Version: 1.9.2
Keywords: Cc:
Blocked by: Blocking:
Description

When using ui datepicker to render 12 inline calendars I have noticed that the beforeShowDay function is duplicating dates ie

29-01-2013

30-01-2013

31-01-2013

01-02-2013

02-02-2013

03-02-2013

28-01-2013

29-01-2013

30-01-2013

31-01-2013

01-02-2013

02-02-2013

03-02-2013

04-02-2013

(see http://stackoverflow.com/questions/14219474/jquery-ui-datepicker-beforeshowday-is-repeating-certain-dates)

the calendars are being updated from a database to show booked days for holiday homes and the above behaviour is causing an issue.

This is the (stripped back) function being called:

function availableDays(date)

{

var m = date.getMonth(),

d = date.getDate(),

y = date.getFullYear();

m = pad(m + 1);

d = pad(d);

var dateId = d + '-' + m + '-' + y;

console.log(dateId)

return [false];

}

I am using jquery.1.8.js and jquery-ui-1.9.2.js

Attachments (0)
Change History (13)

Changed January 09, 2013 10:35AM UTC by Joel comment:1

Here is a jsFiddle -

http://jsfiddle.net/9mR5k/2/

Changed January 09, 2013 01:34PM UTC by tj.vantoll comment:2

milestone: 1.10.01.11.0
status: newopen
summary: Datepicker beforeShowDay repeating dates and outputting in strange orderDatepicker: beforeShowDay repeats dates

Verified. Minified test case - http://jsfiddle.net/tj_vantoll/BCk5K/.

Changed January 09, 2013 02:46PM UTC by scottgonzalez comment:3

owner: → Joel
status: openpending

The repeated dates are for different moths. Notice that the dates coincide with the empty cells that overflow into the previous/next month. I'm not sure this is a bug, so much as a feature change. Why is this causing problems for you?

Changed January 09, 2013 03:27PM UTC by Joel comment:4

status: pendingnew

The problems are caused because I set a range of available booking days, then when a person makes a preliminary booking it goes to the booking start date uses the beforeShowDay to loop over the cells and render as booked the duration you have selected. Because it is matching the start date it needs to be unique but the start date is repeated as are some of the overlapping dates which throws the count out. It is an untidy hack to get around and it would be great to have a straightforward solution.

Changed January 09, 2013 04:12PM UTC by scottgonzalez comment:5

status: newpending

I don't understand why it needs to be unique in that case. Can you provide a reduced example of what you're doing?

Changed January 09, 2013 04:48PM UTC by Joel comment:6

status: pendingnew

It reaches the start date and counts the duration off as the beforeShowDate is looping - when it is reset by reaching the repeated date its position in the calendar is thrown off. Like I say there I can hack around it but would love a cleaner solution.

Sorry, not easy to make an example right now as it is a large .net project and I am a bit strapped for time.

Changed January 09, 2013 04:59PM UTC by scottgonzalez comment:7

Don't worry about the reduced example. I now understand what you're doing. I don't think it's the right way to do it though, as it would break if you turned on showOtherMonths.

Changed January 09, 2013 05:17PM UTC by Joel comment:8

You are quite probably right :) however it isn't persistent just a visual guide to which days are being reserved and it has been holding up fine for dates in the middle of the month. If you have a better solution I would be all ears/grateful

Changed January 09, 2013 06:27PM UTC by scottgonzalez comment:9

You should do actual date math and compare the dates independently, rather than relying on the order in which the callback is invoked.

Changed January 09, 2013 06:34PM UTC by Joel comment:10

Yup - I have ended up doing this - I wasn't aware that you could do a > on a date object. After today I have become very aware of this.

Thanks :)

Changed January 09, 2013 07:02PM UTC by scottgonzalez comment:11

resolution: → patcheswelcome
status: newclosed

I don't think it's worth changing, but we'll accept patches if someone wants to prevent beforeShowDay from being invoked for days outside the current month when showOtherMonths is false (this would need to be introduced in a major release though).

Changed January 14, 2013 04:32PM UTC by Joel comment:12

Sorry to come back on this - could you give me a bit of help with creating a loop that checks that a date hasn't been repeated? Basically, as beforeShowDay requires an array to be returned on each iteration it is throwing an error if I check whether the date has been repeated. Thank you!

Changed January 14, 2013 04:51PM UTC by scottgonzalez comment:13

Please ask for help on the forums or Stack Overflow.