Hello,
I've customized the datepicker configuration to allow just future dates, no weekends or holidays.
The configuration seeems to work fine, and you can have a look at the form here:
http://www.teloaggiusto.io/riparazione-iphone/iphone-4/
datepicker is in the second page of this multi-page form, at the beginning of the page.
It's under a conditional logic: to see it you have to change the very first radio button to "Voglio fissare un'altra data".
As you can see the calendar widget is working fine:
you can select just future days, and no weekends or holidays.
BUT for some reason I cannot figure out, if I try to choose a future date that is more than 15 days in the future, it won't pass the validation, it display the error as the field it's left empty.
I'll paste here the code I use:
1) in functions.php of my template I have this:
add_action('wp_enqueue_scripts', 'enqueue_daterestrict_script', 10, 2);
function enqueue_daterestrict_script() {
wp_enqueue_script('daterestrict_script', get_stylesheet_directory_uri() . '/js/datepicker-restrictions.js', array('jquery'));
}
2) then In the datepicker-restrictions.js file I have all this stuff:
// array of year holidays [month, day]
natDays = [
[1, 1], [1, 6], [4, 25], [5, 1], [6, 2], [8, 15], [11, 1], [12, 8], [12, 25], [12, 26]
];
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1
&& date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return noWeekend;
}
}
jQuery(document).bind('gform_post_render', function(){
if (jQuery(".datepicker").length > 0){
// destroy default Gravity Form datepicker
jQuery(".datepicker").datepicker('destroy');
// create new custom datepicker
jQuery(".datepicker").datepicker({
// Here I customize language of week days and months labels
dayNames: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
dayNamesMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
monthNames: ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"],
dateFormat: "dd-mm-yy",
defaultDate: '+1d',
minDate: '+1d',
gotoCurrent: true,
prevText: '',
showOn: 'both',
buttonImage: 'http://www.teloaggiusto.io/wp-content/themes/teloaggiustoio/images/calendar_icon.png',
buttonImageOnly: true,
beforeShowDay: noWeekendsOrHolidays
});
}
});