Hi guys,
I am running a datepicker on my Pipeline theme. I have tried “everything”. I can only get 1 at a time to work. Meaning either the specific date works, or the noweekend function works. I can not make both of the functions work…
My code for now looks like this:
/* – Code for Cart Date Picker – */
$(document).ready( function() {
$(function() {
var array = [“24-08-2021”,“25-08-2021”,“2013-03-16”]
$(‘input’).datepicker({
minDate: +2,
maxDate: ‘+1M’,
firstDay: 1,
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate(‘dd-mm-yy’, date);
return [ array.indexOf(string) == -1 ]
}
});
});
});
/* - end - */
This is for the exclusion of the dates. Now i want to include the noweekend. can anybody help?
Good Afternoon,
I’ve commandeered and modified a solution I found surfing the high seas of the internet.
It is a little bit verbose, but it should solve your needs of blocking out weekends, as well as specific dates.
Also, it is a bit easier to read this way, rather than me handing you a piece of code that looks like greek, but uses the least amount of characters. lol
And It shouldn’t be too hard for you to add new dates in the future. Just modify the closedDates array to include any future dates you may have.
$(document).ready( function() {
//Initialize the input as a jQuery Ui Date picker
$('input').datepicker({
minDate: +2,
maxDate: '+1M',
firstDay: 1,
//Call the offDays function declared below on the beforeShowDay attribute
beforeShowDay: offDays
});
//This function will declare and disable the required days when called upon
function offDays(date){
//Get the index of each day of the week and store it
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
//Declare which specific dates are closed in an array. Each attribute of the date is an array item as well
var closedDates = [[8, 24, 2021], [8, 25, 2021]];
//Declare your "weekends" or weekly closed days (Could be a tuesday for all the code cares)
var weekends = [[Saturday], [Sunday]];
//Loop through your weekly closed days and return false for each
for (var i = 0; i < weekends.length; i++) {
if (day == weekends[i][0]) {
return [false];
}
}
//Loop through your specific closed dates return false for each
for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
}
});
Also, here is the JSFiddle that I used to test it: https://jsfiddle.net/cwbuxrg6/
Good Afternoon,
Let me know if this helped!
I hope it was able to solve your issue for you.
Thank You,