#8953 closed bug (patcheswelcome)
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
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
Change History (13)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Milestone: | 1.10.0 → 1.11.0 |
---|---|
Status: | new → open |
Summary: | Datepicker beforeShowDay repeating dates and outputting in strange order → Datepicker: beforeShowDay repeats dates |
Verified. Minified test case - http://jsfiddle.net/tj_vantoll/BCk5K/.
comment:3 Changed 10 years ago by
Owner: | set to Joel |
---|---|
Status: | open → pending |
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?
comment:4 Changed 10 years ago by
Status: | pending → new |
---|
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.
comment:5 Changed 10 years ago by
Status: | new → pending |
---|
I don't understand why it needs to be unique in that case. Can you provide a reduced example of what you're doing?
comment:6 Changed 10 years ago by
Status: | pending → new |
---|
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.
comment:7 Changed 10 years ago by
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
.
comment:8 Changed 10 years ago by
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
comment:9 Changed 10 years ago by
You should do actual date math and compare the dates independently, rather than relying on the order in which the callback is invoked.
comment:10 Changed 10 years ago by
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 :)
comment:11 Changed 10 years ago by
Resolution: | → patcheswelcome |
---|---|
Status: | new → closed |
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).
comment:12 Changed 10 years ago by
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!
Here is a jsFiddle -
http://jsfiddle.net/9mR5k/2/