I'm using jQuery UI datepicker for a form where users request a tour of the school. There is a date range that the tours are being held, and within that range the site admin may disable certain days that are booked. No problem so far:
/* array of booked dates generated from CMS backend */
var disabledDates = [
'2015-05-06',
'2015-05-08' // examples
];
$('[name="date_of_visit"]').datepicker({
minDate: '4/30/2015', // Range start
maxDate: '10/1/2015', // Range end
beforeShowDay: function(date) { // Disable custom dates
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [$.inArray(string, disabledDates) == -1];
}
});
I got the beforeShowDay
code from this post: Jquery UI datepicker. Disable array of Dates
I know I can add a class to the disabled elements with the second parameter but it adds it to all the disabled dates, including those outside of minDate
and maxDate
:
beforeShowDay: A function that takes a date as a parameter and must return an array with:
0: true/false indicating whether or not this date is selectable
1: a CSS class name to add to the date's cell or "" for the default presentation
2: an optional popup tooltip for this dateThe function is called for each day in the datepicker before it is displayed.
However the client has requested that only the "booked" dates have a visual indication that the date is not available (distinct from the default disabled state). There will not be many, maybe 4 or 5. It makes sense to me.
Is there some way to customize only the dates disabled by the beforeShowDay
function in my setup, or another solution to achieve what I'm after? jsFiddle demo