fullcalendar not showing event base on event time - javascript

I am building a event calendar within Hero Framework. I have got my fullcalendar linked to DB via JSON method. The record is showing start at "2012-04-18 12:00" and end at "2012-04-18 14:00" but calendar failed to show the event base on the time. It is shown as ALL-DAY event. Any idea how to solve that?
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
allDaySlot: false,
firstHour: 9,
select: function(start, end) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end
},
false // make the event "stick"
);
var startDateString = $.fullCalendar.formatDate(start, 'yyyy-MM-dd hh:mm');
var endDateString = $.fullCalendar.formatDate(end, 'yyyy-MM-dd hh:mm');
$.ajax({
type: 'POST',
url: '{url}ajaxpost/add',
data: {
startDate: startDateString,
endDate: endDateString,
eventTitle: title
},
dateType: 'json',
success: function (resp) {
calendar.fullCalendar('refetchEvents');
}
});
}
calendar.fullCalendar('unselect');
},
editable: true,
events: "{url}ajaxget/data",
});
});

you need to set the event allDay property to false

When you return the events from your {url}ajaxget/data url, you need to specify that the event is not all day.
You do this my setting an allDay field on each event that is not all day long.
It may look like this:
[{
start : 10000000,
end : 10000500,
title : 'example event'
allDay : false
}, ... ]
You can also find this info in the documentation.

Related

Object array argument isn't being understood by FullCalendar object

I'm populating an object array from an ajax call using jQuery, in order to display event data from our system into the calendar. For some reason, it won't recognize it as events, and they aren't being displayed on the calendar. See code below.
I've checked it over 100 times, and I'm sure the data is coming in the correct format. The events variable is also not empty at runtime.
var events = [];
$.ajax({
type: 'GET',
url: "ajax/shared.ashx",
dataType: 'json',
data: 'm=get-staff-schedule',
success: function (json) {
console.log(json);
$.each(json.response.data, function (i, app) {
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
startTime: app.time_in,
endTime: app.time_out
});
});
renderCalendar(events);
}
});
function renderCalendar(events) {
var calendarEl = document.getElementById('calendar');
var d = new Date();
var date = d.getFullYear() + '-' + padDigits(d.getMonth() + 1, 2) + '-' + padDigits(d.getDate(), 2)
debugger
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid', 'timeGrid', 'bootstrap'],
themeSystem: 'bootstrap',
defaultView: 'timeGridWeek',
defaultDate: date,
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
events: events
});
calendar.render();
}
Here is the image of the rendered, blank, calendar. Also, here are FullCalendar's docs for reference: https://fullcalendar.io/docs/event-parsing
replace
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
startTime: app.time_in,
endTime: app.time_out
});
by
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
start: app.time_in,
end: app.time_out
});
I figured it out! Only took me like 2 hours!
Basically, this object requires all strings. So, the daysOfWeek value needed to be converted from an integer to a string. Here is what I did:
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: (app.day - 1) + '',
startTime: app.time_in,
endTime: app.time_out
});

Fullcalendar doesn't work

I like the fullcalendar JQuery-Plugin. My calendar doesn't work. At the moment i am looking for a solution to add an event but i can't... Why ?
This is my code:
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultDate: '2017-05-11',
editable: true,
selectable: true,
selectHelper: true,
eventLimit: true, // allow "more" link when too many events
select: function(start, end, allDay) {
var title = prompt("Event here: ", "New Event:");
if (title != null) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
$calendar.fullCalendar("unselect");
},
events: [
{
title: 'All Day Event',
start: '2017-05-01'
}
]
});
});
You need to define variable calendar like below
var calendar = $('#calendar').fullCalendar({
Then it will work.

Getting the event id in fullcalendar object event

I am using http://fullcalendar.io/
My user can create multiple events to indicate his disponibilities. Everytime he selects a slot, he is creating an event :
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
lang: "fr",
header: false,
timezone: 'local',
minTime: "08:00:00",
columnFormat: 'dddd',
selectHelper: true,
selectable: true,
select: function(start, end, id, allDay) {
var eventData = {
start: start,
end: end,
block: true,
editable: true,
id: id,
backgroundColor: "#469278"
};
// console.log(moment(eventData.start["_d"]).format("dddd"));
// console.log(moment(eventData.end["_d"]).format("dddd"));
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
// console.log(eventData);
// if (moment(eventData.start["_d"]).format("dddd") != moment(eventData.end["_d"]).format("dddd")) {
// $('#calendar').fullCalendar('unselect');
// };
var day = moment(eventData.start["_d"]).format("dddd");
var start_time = moment(eventData.start["_d"]).format("HH:mm");
var end_time = moment(eventData.end["_d"]).format("HH:mm");
var id = moment(eventData.end["_id"]);
var slot = {
day: day,
start_time: start_time,
end_time: end_time
};
array_dispo.push(slot);
$("#dispo_array").val(JSON.stringify(array_dispo));
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true,
eventClick: function(event, element) {
if(confirm('Voulez-vous supprimer cette dispo?')) {
$('#calendar').fullCalendar('removeEvents',event._id);
}
},
selectOverlap: function(event) {
return ! event.block;
}
});
});
// console.log(moment(eventData.start["_d"]).format("dddd"));
// console.log(moment(eventData.end["_d"]).format("dddd"));
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
// console.log(eventData);
// if (moment(eventData.start["_d"]).format("dddd") != moment(eventData.end["_d"]).format("dddd")) {
// $('#calendar').fullCalendar('unselect');
// };
var day = moment(eventData.start["_d"]).format("dddd");
var start_time = moment(eventData.start["_d"]).format("HH:mm");
var end_time = moment(eventData.end["_d"]).format("HH:mm");
var id = moment(eventData.end["_id"]);
var slot = {
day: day,
start_time: start_time,
end_time: end_time
id: id
};
array_dispo.push(slot);
$("#dispo_array").val(JSON.stringify(array_dispo));
$('#calendar').fullCalendar('unselect');
},
Everytime a user selects a timeslot, it creates an Event Object http://fullcalendar.io/docs/event_data/Event_Object/ with the eventData I specified that is sent as a JSON in a hidden field. Problem is I didnt manage to get the id of this event object that I suppose is sent by fullcalendar.
The object I get when I do console.log(eventData); is :
Object {start: Moment, end: Moment, id: jQuery.Event, block: true, editable: true…}
but this jQuery.event doesnt have a unique id, it looks like this :
id: jQuery.Event
altKey: false
bubbles: true
button: 0
buttons: 0
cancelable: true
clientX: 336
clientY: 290
ctrlKey: false
I need this id if I want to delete or modify an event object later on.
How can I get this event id ?
You specify your own id in the eventData object, it's 1 in the example you've given. Make sure to have these unique and then you can pass this id to .fullCalendar( 'removeEvents' [, idOrFilter ] ) for example.
Find examples of creating unique id's at: Create GUID / UUID in JavaScript?

Json data not displaying correctly

I have fullcalendar with some JSON data. It shows up as "12a Medical Day Jackson Post". Otherwise the display is fine. When I change the dates to be "start":"12/2/2015" to this 2015-2-12. The 12a appen disappears.
The Code for fullcalendar used is this
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek'
},
defaultDate: '2015-03-11',
defaultView: 'month',
selectable: false,
selectHelper: false,
select: function(start, end) {
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true, // allow "more" link when too many events
eventMouseover: function(event, jsEvent, view) {
if (view.name !== 'agendaDay') {
$(jsEvent.target).attr('title', event.title);
}
},
events:[
{
"title":"Medical Day Jackson Post",
"start":"12/2/2015",
"end":"12/3/2015",
"description":"Jackson"
},
By default it shows the time unless the event is an allDay event. If allDay isn't specified, it guesses and in your case, it guessed differently depending on the date format.
So, either make allDay explicit in you events, or stop the time from displaying on all events with timeFormat: "", as one of you fullCalendar options.

How to make fullcalendar do a selection twice?

I want to make two selections in the calendar. Right now I can only make one that goes to one of my inputs.
I am trying to select a date on the calendar, then that first selection goes to my first input tag.
Then after that I want to select a different date that goes to my second input tag.
So basically, I want to make two selections. Here is my code. Do I need to make a callback somewhere here? I put my code on jsfiddle.
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = 'true';
if (title === 'true') {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
var eventStart = $.fullCalendar.formatDate(start, "MM/dd/yyyy");
var eventEnd = $.fullCalendar.formatDate(end, "MM/dd/yyyy");
$('input[name="startDate"]').val(eventStart);
}
calendar.fullCalendar('unselect');
},
eventClick: function(calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', calEvent._id);
$('input[name="startDate"]').removeAttr('value');
$('input[name="endDate"]').removeAttr('value');
},
editable: true
});
Unless I'm not understanding your question, how about doing this?
if($('input[name="startDate"]').val()=='') {
$('input[name="startDate"]').val(eventStart);
} else {
$('input[name="endDate"]').val(eventEnd);
}
JSFIDDLE

Categories

Resources