fb_pixel

How to make a ban on the choice of multiple date ranges in jquery.datepicker?

Development | Web Development
Description
Hello everyone.

To make it clear what is at stake - a calendar for recording on the service station, which has free and busy hours

It may be that in one day free time only from 9-10, 12-16, 17-18 and the user can select the date and time, only in free time

How to block multiple date ranges in a datepicker at once?
Attachments
No attachments
Info
Description
The solution is simple, disable specified days...

Source: https://davidwalsh.name/jquery-datepicker-disable-days

/* create an array of days which need to be disabled */
var disabledDays = ["2-21-2010","2-24-2010","2-27-2010","2-28-2010","3-3-2010","3-17-2010","4-2-2010","4-3-2010","4-4-2010","4-5-2010"];

/* utility functions */
function nationalDays(date) {
	var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
	for (i = 0; i < disabledDays.length; i++) {
		if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > date) {
			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
			return [false];
		}
	}
	//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
	return [true];
}
function noWeekendsOrHolidays(date) {
	var noWeekend = jQuery.datepicker.noWeekends(date);
	return noWeekend[0] ? nationalDays(date) : noWeekend;
}

/* create datepicker */
jQuery(document).ready(function() {
	jQuery('#date').datepicker({
		minDate: new Date(2010, 0, 1),
		maxDate: new Date(2010, 5, 31),
		dateFormat: 'DD, MM, d, yy',
		constrainInput: true,
		beforeShowDay: noWeekendsOrHolidays
	});
});

on January 16th, 2020 (7:10 pm)
All coments
This job has not been commented yet.