How can I render blocked dates from db into calendar? Currently I do by hardcode. Is there any solution can I use to solve this problem? Here I attached the the code and script.
Thanks
The code:
SCRIPT:
$(document).ready(function () {
//Blocked date
var disableddates = ["2018-02-17","2018-03-21","2018-05-01","2018-03-02","2018-03-22","2018-03-30","2018-03-31","2018-04-20","2018-04-14","2018-04-21","2018-04-05","2018-04-18","2018-04-11","2018-02-21","2018-04-26","2018-04-30","2018-04-27"];
function DisableSpecificDates(date)
{
var y = date.getFullYear();
var m = date.getMonth();
var d = date.getDate();
// First convert the date in to the mm-dd-yyyy format
// Take note that we will increment the month count by 1
var currentdate = y + '-' + (m + 1) + '-' + d ;
// We will now check if the date belongs to disableddates array
for (var i = 0; i < disableddates.length; i++) {
// Now check if the current date is in disabled dates array.
if ($.inArray(currentdate, disableddates) != -1 ) {
return [false];
}
}
// In case the date is not present in disabled array, we will now check if it is a weekend.
// We will use the noWeekends function
var weekenddate = $.datepicker.noWeekends(date);
return weekenddate;
}
$(".form").validate({
submitHandler: function (form) {
form.submit();
}
});
$('.txtStartDate').datepicker({
minDate: 30,
//maxDate: 30,
beforeShowDay: DisableSpecificDates
}).on('change', function () {
var startDate = $('.txtStartDate').val();
var dateStartDate = new Date(startDate);
var currentDate = new Date();
var oneMonthDate = new Date(new Date(currentDate).setMonth(currentDate.getMonth() + 1))
if (dateStartDate <= oneMonthDate) {
alertify.error("You can only select 1 months in advance.");
$('.txtStartDate').val("");
}
});
$('.txtEndDate').datepicker({
minDate: 30,
//maxDate: 30,
beforeShowDay: DisableSpecificDates
}).on('change', function () {
var startDate = $('.txtStartDate').val();
var endDate = $('.txtEndDate').val();
var dateStartDate = new Date(startDate);
var dateEndDate = new Date(endDate);
if (dateStartDate > dateEndDate || startDate == "") {
alertify.error("Invaild End Date");
//$('.txtStartDate').val("");
$('.txtEndDate').val("");
$("#div_end_date").insertBefore($("#div_Time_Slot_Table"));
document.getElementById("div_Time_Slot_Table").style.display = "none";
}
Amit KumarPosted May 14, 2018, 11:45 PM