https://jsfiddle.net/studovey/jvrwfzea/21/
Im getting the following error in FullCalendar.js every time I select Day view I get this error. There is an event on the below date so it throws the error.
I thought that it could be something to do with the formatting perhaps. I have looked online for solution but to no avail.
Can anyone share any throughts?
My code is the following:
function GetAppointments() {
var initialLocaleCode = 'en';
$('#calender').fullCalendar('destroy');
$('#calendar').fullCalendar({
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonText: {
today: 'Today',
month: 'Month',
week: 'Week',
day: 'Day'
},
footer: true,
selectable: true,
height: 650,
events: function (start, end, timezone, callback) {
$.ajax({
type: "GET",
contentType: "application/json",
url: '#Url.Action("GetAppointmentData", "Admin")',
dataType: "JSON",
selectable: true,
locale: 'en',
titleFormat: "YYYY-MM-DD HH:mm:ss",
success: function (data) {
var events = [];
$.each(data, function (i, data) {
var start = data.start;
var end = data.end;
events.push({
eventID: data.Id,
title: data.title,
description: data.description,
start: start,
end: end,
backgroundColor: data.type.TypeColour,
textColor: 'white',
borderColor: 'white',
allDay: false,
});
});
callback(events);
}
})
},
nextDayThreshold: '00:00:00',
editable: true,
droppale: true,
nowIndicator: true,
eventClick: function (info) {
GetEventDetailByEventId(info);
}
});
$(".fc-day-header").addClass("bg-success");
$(".fc-day-header").css("color", "white");
$(".fc-button, .fc-agendaWeek-button, .fc-state-hover").addClass("bg-success");
}
// Grab individual elements from the combined HTML string. Use each as the default rendering.
// Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false.
$(html).each(function (i, node) {
var seg = segs[i];
var el = view.resolveEventEl(seg.event, $(node));
if (el) {
el.data('fc-seg', seg); // used by handlers
seg.el = el;
renderedSegs.push(seg);
}
});
}
function GetEventDetailByEventId(eventinfo) {
$.ajax({
type: "POST",
url: '#Url.Action("GetAppointmentById", "Admin")',
dataType: "JSON",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
'id': eventinfo.id
}),
success: function (data) {
$('#appointmentHeader').removeClass('bg-success');
$('#appointmentHeader').addClass('bg-info');
$('#btnUpdate').removeClass('d-none');
$('#btnDelete').removeClass('d-none');
$('#btnAdd').addClass('d-none');
$('#headerText').html('Update Appointment');
$('#btnBackAdd').removeClass('d-none');
$('#txtTitle').val(data.Name);
$('#txtName').val(data.Info);
$('#txtStartDate').val(moment(data.StartTime).format("DD-MM-YYYY HH:mm"));
$('#txtEndDate').val(moment(data.EndTime).format("DD-MM-YYYY HH:mm"));
$('#hdnAppointmentId').val(data.Id);
$('#drptype').val(data.type.Id);
}
})
}
Did you check whether you are getting the expected values for data.StartTime and data.EndTime that you are passing into the function? The error event of undefined might be coming from moment. I faced that once.
Related
I use one source from PHP and it's work thine ! (i'm on fullcalendar v3)
> $('#calendar').fullCalendar({
events: {
url: myevents.php,
type: 'GET',
data: {
param: parametreFilter
},
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
lazyFetching: false,
editable: true,
droppable: true, ...
Now i would like to add events from another source. A gouvernemental API that display holidays. So i tried a lot of things and nothing works:
$('#calendar').fullCalendar({
eventSources:[
// your event source
{
url: 'https://calendrier.api.gouv.fr/jours-feries/metropole.json',
type: 'GET',
},
{
url: myevents.php,
type: 'GET',
data: {
param: parametreFilter
}
},
],
eventDataTransform:function(eventData){
console.log("YEP: " + JSON.stringify(eventData)); /* I tried this but the source from API never come in that function */
return eventData;
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
lazyFetching: false,
editable: true,
droppable: true,
dragScroll: true,
defaultView: 'agendaWeek',...
I saw this too: https://codepen.io/acerix/pen/EQePxq?editors=0010 But i can't apply it to my example.
I forgot something: I wrote a function to format the events from API, but i think that when i use it, the fullcalendar render is already finish before i get the events from API and reformat them. So its never displayed.
myholidays = []
function getHolidays(url) {
fetch(url)
.then(function(res) {
if (res.ok) {
return res.json().then(function(days) {
/*console.log(jours)*/
let i = 0
let holidays = []
for (const day in days) {
/*console.log(`${day}: ${days[day]}`);*/
holidays.push({ "title": days[day], "start":day+'T00:00:00', "allDay": true})
i++
}
myholidays.push.apply(feries,joursferies)
$('#calendar').fullCalendar( 'refetchEvents' );
})
}
else{
console.log("Error")
}
})
.catch(function(err) {
alert("Error: " + err)
});
}
Can you please help ?
The data at https://calendrier.api.gouv.fr/jours-feries/metropole.json is not an array containing objects in fullCalendar's event format so it will never display them.
You need to use the events-as-a-function option to download the data via your own AJAX request, and then process it into the correct format:
Your attempt above had one or two little mistakes in it, and also doesn't actually insert anything to the calendar, but it was a useful basis for a working solution:
eventSources: [
function (start, end, timezone, callback) {
fetch("https://calendrier.api.gouv.fr/jours-feries/metropole.json")
.then((response) => response.json())
.then(function (data) {
let holidays = [];
for (const day in data) {
holidays.push({
title: data[day],
start: day,
allDay: true
});
}
callback(holidays);
});
},
{
url: "myevents.php",
type: "GET",
data: {
param: parametreFilter
}
}
]
Demo: https://codepen.io/ADyson82/pen/eYvzqOp?editable=true&editors=001
I have been getting an error when I want to add an event on fullcalendar, my code is correct because the console detects the day I click on it.
I looked at the topics that dealt with the same error but none of them allowed me to solve this error.
Except that an error occurs:
console
And here is my code :
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'fr',
editable: true,
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
events: 'http://127.0.0.1:8000/calendar',
displayEventTime: false,
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Nom événement :');
if (title) {
var start = new Date().toISOString().slice(0, 10);
var end = new Date().toISOString().slice(0, 10);
$.ajax({
url: 'http://127.0.0.1:8000/calendarAjax',
data: {
title: title,
start: start,
end: end,
type: 'add',
},
type: 'POST',
success: function(donnees) {
calendar.fullCalendar('renderEvent', {
id: donnees.id,
title: title,
start: start,
end: end,
allDay: allDay
}, true);
calendar.fullCalendar('unselect');
}
});
}
},
});
calendar.on('dateClick', function(info) {
console.log('clicked on ' + info.dateStr);
});
calendar.render();
});
</script>
Thank you.
I'm trying to render events on the fullcalendar from the json response,
$.ajax({
url : $("body").attr("data-link")+'/calendar/events',
type : 'post',
dataType: 'json',
success: function(e){
if(e.success){
var events = [];
$.each(e.events,function(index,value){
events.push({
title : value.title,
start : moment(value.start_date).format('YYYY-MM-DD'),
end : moment(value.end_date).format('YYYY-MM-DD'),
});
});
calendar.fullCalendar( 'renderEvent', events , true);
console.log(events);
}
}
});
here's my fullcalendar set up
var calendar = $('#calendar').fullCalendar({
customButtons: {
myCustomButton: {
text: 'Add Event',
click: function() {
}
}
},
header: {
left: 'prev,next today myCustomButton',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable : false,
eventLimit: true,
eventClick: function(calEvent, jsEvent, view, element) {
},
eventRender: function(event, element) {
element.attr("data-id",event.id);
},
});
In the console log.
and then it gives me this error,
Uncaught TypeError: Cannot read property 'hasTime' of undefined
any ideas, help please?
You could either call renderEvent for each event in events or add entire array as datasource
$.ajax({
url : $("body").attr("data-link")+'/calendar/events',
type : 'post',
dataType: 'json',
success: function(e){
if(e.success){
var events = [];
$.each(e.events,function(index,value){
events.push({
title : value.title,
start : moment(value.start_date).format('YYYY-MM-DD'),
end : moment(value.end_date).format('YYYY-MM-DD'),
});
});
calendar.fullCalendar( 'addEventSource', events);
}
}
});
FullCalendar v2.2.5, I want to use my JSON generating script to pull data only for the visible area of the calendar as mentioned in a few other questions.
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay',
defaultAllDay: true,
},
lazyFetching: false,
defaultDate: '2015-01-06',
editable: false,
eventLimit: 10,
weekMode: 'liquid',
dayPopoverFormat: 'DD/MM/YYYY',
//events: {
// url: 'instant-tools.cgi',
// type: 'POST',
// data: {
// events: 1,
// pending: 1,
// from: '2014-01-01',
// to: '2016-12-31',
// }
// },
viewRender: function(view, element) {
var events_slice = new Object();
events_slice.eventSources = [
{
url: 'instant-tools.cgi',
type: 'POST',
data: { events: 1, pending: 1, from: '2014-01-01', to: '2016-12-31' }
}
];
$('#calendar').fullCalendar('addEventSource', events_slice);
//$('#calendar').fullCalendar('renderEvents');
},
eventClick: function(calEvent, jsEvent, view) {
alert(calEvent.title + "n" + calEvent.start.format('DD/MM/YYYY') + " to " + calEvent.end.format('DD/MM/YYYY'));
},
});
});
The commented out events definition works (when I use it) but the viewRender one does not. Before you ask viewRender does get triggered. I get no errors in the console and no events displayed. My script is not called at all. I know I have the dates hardcoded right now but I will use view.intervalStart and view.intervalEnd once I verify I get a similar result. Having $('#calendar').fullCalendar('renderEvents'); in there makes no difference, also toggling lazyFetching does not make a difference. Not a JS coder so I hope I'm just being silly somewhere.
in the event property you need to call the function
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay',
defaultAllDay: true,
},
lazyFetching: false,
defaultDate: '$today',
editable: false,
eventLimit: 10,
weekMode: 'liquid',
dayPopoverFormat: 'DD/MM/YYYY',
events: function(start, end, timezone, callback) {
$.ajax({
url: 'instant-tools.cgi',
data: {
events: 1,
pending: 1,
from: '2014-01-01',
to: '2016-12-31',
},
success: function(doc) {
var obj = jQuery.parseJSON(doc);
var events = [];
$.each(obj, function(index, value) {
events.push({
id: value['id'],
//all data
});
//console.log(value)
});
callback(events);
},
error: function(e, x, y) {
console.log(e);
console.log(x);
console.log(y);
}
});
},
eventClick: function(calEvent, jsEvent, view) {
alert(calEvent.title + "n" + calEvent.start.format('DD/MM/YYYY') + " to " + calEvent.end.format('DD/MM/YYYY'));
},
});
});
Seems that on several entries, provides me with a link to show the remain items "+## more".
Currently when clicking on link to expand and view all items, its returning an empty dialogue.
The versión fullCalendar is: 2.1.1
The problem is with these propertys: allDayDefault: true, or in event allDay:true, when clicking on link to expand and view all items.
Im started the calendar with:
<script type="text/javascript">
$('#calendar').fullCalendar
({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
selectable: true,
selectHelper: true,
allDayDefault: true,
eventSources: [getCalData()],
});
function getCalData() {
var urlAux = baseUrl + '/pagweb/WSAgenda.asmx/test';
var source = [{}];
$.ajax({
async: false,
type: "POST",
contentType: "application/json",
data: "{}",
url: urlAux,
dataType: "json",
success: function (data) {
if (data.d != null) {
for (var i = 0; i < data.d.length; i++) {
source.push({
id: data.d[i].id,
start: new Date(data.d[i].start),
end: new Date(data.d[i].end),
title: data.d[i].title,
className: data.d[i].color,
});
};
}
else {
return null;
}
}
});
return source;
}
});
</script>
getCalData is a json request.