I'm trying to update info date event from modal Bootstrap in Fullcalendar version 4. My test:
- Read event json
- Click on event calendar, open modal, show info event and set value of a field with information to update
- When I click on green button "Salva" (Save), doSubmitEdit function is called. It should:
- close modal;
- receive text field edited;
- update via ajax my db;
- update calendar event if necessary
But when then button is clicked I have this error:
q TypeError: calendar.fullCalendar is not a function on this line: var event_obj_arr = calendar.fullCalendar('clientEvents', calendario_id);
(function ($) {
'use strict';
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'it',
plugins: ['dayGrid', 'timeGrid', 'list', 'interaction', 'bootstrap'],
themeSystem: 'bootstrap',
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectMirror: true,
editable: true,
eventLimit: true, // allow "more" link when too many events
events: {
url: '/_admin/vendor/fullcalendar/php/get-events.php',
failure: function () {
document.getElementById('script-warning').style.display = 'block';
}
},
eventClick: function (info) {
$('.card-body h4').html(info.event.start.toDateString());
$('.card-body p').html(info.event.title + '<br>' + info.event.extendedProps.autista + ' / Info: ' + info.event.extendedProps.autista_description);
$('#calendario_id').val(info.event.id);
$('#btnModal').trigger('click');
},
loading: function (bool) {
document.getElementById('loading').style.display =
bool ? 'block' : 'none';
}//,
});
calendar.render();
$('#submitButtonEdit').on('click', function (e) {
// We don't want this to act as a link so cancel the link action
e.preventDefault();
doSubmitEdit();
});
function doSubmitEdit() {
// get event object
var event_obj_arr = calendar.fullCalendar('clientEvents', calendario_id);
var event_obj = event_obj_arr[0];
// edit
$("#createEventModalEdit").modal('hide');
console.log($('#autista_description').val());
console.log($('#calendario_id').val());
// update event object properties
event_obj.extendedProps.autista_description = $('#autista_description').val();
// post to server
$.ajax({
url: '/_admin/vendor/fullcalendar/php/planning-aggiorna.asp',
data: 'type=changetitle&title=' + title + '&calendario_id=' + calendario_id,
type: 'POST',
dataType: 'json',
success: function (response) {
if (response.status == 'success') {
// nothing to do here
// update calendar, you may put this line into success method
calendar.fullCalendar('updateEvent', event_obj);
}
},
error: function (e) {
alert('Error processing your request: ' + e.responseText);
}
});
}
}).apply(this, [jQuery]);
Is it possibile to access fullcalendar class outside of it? Thank you.
calendar.fullCalendar('clientEvents'
is the old syntax and method name from v3. As per the upgrade guide the replacement in v4 is getEvents, you'd write it asvar event_obj_arr = calendar.getEvents());
. You'll have a similar issue withcalendar.fullCalendar('updateEvent'
later on in your code. Study the upgrade guide and make sure you understand all the differences between v3 and v4! – ADysoncode
// get values from modal form var calendario_id = $('#calendario_id').val(); var calendario_descrizione = $('#calendario_descrizione').val(); // get event object by id var event = calendar.getEventById(calendario_id); var title = event.title; // update calendar in case of 'success' event.setProp('title', title + ' changed'); event.setExtendedProp('autista_description', calendario_descrizione); – Roby72