I am creating a booking calendar and ran into a problem. I can't render the full calendar after Ajax responses. In response, he receives two arrays with numbers, one array defines which days of the week are available, e.g. (1 and 6, i.e. from Monday to Saturday) - here I use the hiddendays function, but I cannot dynamically pass data to it. At the same time, in the second table I have specific dates that are no longer available, so I want to exclude them from clicking on them, but I do not know what function to use.
$(document).ready(function () {
let startServiceDay = 0;
let endServiceDay = 0;
const calendarEl = document.getElementById("calendar");
/* AJAX FULL CALENDAR */
$("select#select-service").change(function () {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
method: "POST",
url: getFreeDay + $(this).val(),
data: {
"id": $(this).val()
},
beforeSend: function () {
$(".calendary-loader").css('display', 'block');
},
})
.done(function (data) {
data:data.hiddenDays,
data.startServiceDay = data.hiddenDays[0]['service_day_of_week_start'],
data.endServiceDay = data.hiddenDays[0]['service_day_of_week_end'],
calendar.render();
$(".calendary-loader").css('display', 'none');
console.log(startServiceDay + ' ' + data.endServiceDay);
//window.location.reload();
})
.fail(function (data) {
console.log($(this).data('id'))
console.log(data.responseJSON.message);
});
});
let calendar = new Calendar(calendarEl, {
//const m = moment();
locale: plLocale,
plugins: [dayGridPlugin, timeGridPlugin, listPlugin, interactionPlugin, momentPlugin],
initialView: 'dayGridMonth',
headerToolbar: {
left: 'prev,next',
center: 'title',
right: ''
},
editable: true,
hiddenDays: [startServiceDay, endServiceDay],
/*dayRender: function(date, cell){
if (date > maxDate){
$(cell).addClass('disabled');
}
},*/
selectable: true,
selectAllow: function (select) {
return moment().diff(select.start, 'days') <= 0
}
});
});