I'm currently working on a booking form that involves the jQuery UI Datepicker. I've encountered a major issue that I could use some assistance with: There are certain trips where only specific days are available for booking, and these trips can only be sold during certain months due to factors like cyclone season.
While I have successfully managed to disable specific weekdays using a function, I am unsure about how to deactivate entire months such as October. Is this even possible?
I would greatly appreciate any advice on this matter. Below is a snippet of my code. Please let me know if further clarification or additional parts of the code are needed. Thank you in advance!
$.datepicker.setDefaults( $.datepicker.regional[ getLanguage() ] );
$( "#booking" ).datepicker({
showOn: "button",
dateFormat : 'yy/mm/dd',
buttonText: "Select",
beforeShowDay: disableSpecificWeekDays,
changeMonth: true,
changeYear: true,
minDate: 0
}
);
// 0 = monday, 1 = tuesday, 2 = wednesday, 3 = thursday, 4=friday, 5 = saturday, 6=sunday
var daysToDisable = [1, 4, 6];
function disableSpecificWeekDays(date) {
var day = date.getDay();
for (i = 0; i < daysToDisable.length; i++) {
if ($.inArray(day, daysToDisable) != -1) {
return [false];
}
}
return [true];
}
Using the provided code, I am able to disable specific dates. However, when it comes to deactivating an entire month, the process becomes cumbersome as I would need to specify each individual date. In some cases, I may need to deactivate multiple months for a single trip.
var $disableMonths = new Array("2013/10/01","2013/10/02","2013/10/03", "...");
function disableSpecificMonths(mydate){
var $return = true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('yy/mm/dd', mydate);
for(var i = 0; i < $disableMonths.length; i++) {
if($disableMonths[i] == $checkdate) {
$return = false;
$returnclass= "unavailable";
}
}
return [$return,$returnclass];
}
If disabling an entire month proves to be impossible, I am open to suggestions on how to combine the functions for deactivating specific weekdays and specific dates. This way, I could effectively manage both restrictions simultaneously.