Event ToolTip not displaying in FullCalendar - fullcalendar

I've been working with the FullCalendar configuration for a little bit now but I've reached a point that I just can't get figured out. I want to enable to tooltips to appear when the end user hovers over the event. I would like to give a little further information in the tooltip for the event, such as a phone contact number, etc.
I've tried a number of different options that I was able to find.
The list of links below for example.
FullCalendar event popup
http://jsfiddle.net/m54g5aen/
Fullcalendar / eventdidmount - issue with "more link"
I'll pulling in my events via a JSON array from a PHP script.
Here is my Calendar rendering code.
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
height: 550,
slotDuration: {minutes: 15},
nowIndicator: true,
allDaySlot: false,
eventBackgroundColor: '#916FDF',
slotMinTime: "08:00:00",
slotMaxTime: "20:00:00",
displayEventEnd: false,
initialView: 'timeGridWeek',
events: <?php print json_encode($events); ?>,
eventDidMount: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
},
customButtons: {
addNewAppointment: {
text: 'New Appt',
click: function() {
window.location.href="../client/newAppointment.php";
}
}
},
headerToolbar: {
left: 'title',
center: 'dayGridMonth timeGridWeek',
right: 'prev next today addNewAppointment'
}
});
calendar.render();
});
</script>
My PHP to pull the events is as follows:
<?php
require_once('../db_connect.php');
// Check to see if the session is already started.
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$query = 'SELECT
CONCAT(client.cl_fName, " ", client.cl_lName) AS "title",
CONCAT(appointment.sched_date,"T", appointment.start_time) AS "start",
CONCAT(appointment.sched_date,"T", appointment.end_time) AS "end",
CONCAT("TEST", " DESCRIPTION") AS "description"
FROM
appointment, client
WHERE appointment.client_id = client.client_id';
$statement = $db1->prepare($query);
$statement->execute();
$events = $statement->fetchAll();
$statement->closeCursor();
?>
I appreciate all suggestions. Thank you in advance.

Try using a popover instead of a tooltip, it's better than a tooltip if you wanna add more info to it.
change youreventDidMount to
eventDidMount: function (info) {
$(info.el).popover({
title: info.event.title,
placement: 'top',
trigger: 'hover',
content: 'more info on the popover if you want',
container: 'body'
});
}

Related

onDragStop tells me jsEvent is undefined

I'm trying to make it possible to drag events to an external div and back into the calendar again. However, whenever I drop an event I get TypeError: jsEvent is undefined.
I'm not entirely sure why it is doing this, this should be a valid parameter that is passed to the function of eventDragStop.
I'm using the latest FullCalendar 4.
Here is my code
// Load the CSS stuff
import {Tooltip} from "bootstrap";
require('#fortawesome/fontawesome-free/css/fontawesome.min.css');
require('#fortawesome/fontawesome-free/css/brands.min.css');
require('#fortawesome/fontawesome-free/css/solid.min.css');
require('../css/app.scss');
// Load the JS stuff
let $ = require('jquery');
require('bootstrap');
require('./libs/navbar.js');
require('jquery-ui/ui/widgets/draggable');
import apiclient from "./libs/apiclient";
import { Calendar } from '#fullcalendar/core';
import dayGridPlugin from '#fullcalendar/daygrid';
import timeGridPlugin from '#fullcalendar/timegrid';
import interactionPlugin from '#fullcalendar/interaction';
import bootstrapPlugin from '#fullcalendar/bootstrap';
// $(document).ready(function () {
//
// });
document.addEventListener('DOMContentLoaded', () => {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
let calendarEl = document.getElementById('calendar-holder');
let calendar = new Calendar(calendarEl, {
views: {
jira: {
type: 'dayGridWeek',
duration: {months: 3},
buttonText: 'Jira'
}
},
defaultView: 'jira',
themeSystem: 'bootstrap',
editable: true,
droppable: true,
firstDay: 1,
contentHeight: 'auto',
weekNumbersWithinDays: true,
weekNumbers: true,
eventSources: [
{
url: "/fc-load-events",
method: "POST",
extraParams: {
filters: JSON.stringify({})
},
failure: () => {
// alert("There was an error while fetching FullCalendar!");
},
},
],
header: {
left: 'prev,next today',
center: 'title',
right: 'jira,dayGridMonth,timeGridWeek',
},
plugins: [ bootstrapPlugin, interactionPlugin, dayGridPlugin, timeGridPlugin ], // https://fullcalendar.io/docs/plugin-index
timeZone: 'UTC',
eventRender: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.title+'<br>'+info.event.extendedProps.assignee,
placement: 'top',
trigger: 'hover',
container: 'body',
html: true
});
},
dragRevertDuration: 0,
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventDragStop: function( event, jsEvent, view ) {
if(isEventOverDiv(jsEvent.clientX, jsEvent.clientY)) {
$('#calendar-holder').calendar('removeEvents', event._id);
var el = $( "<div class='fc-event'>" ).appendTo( '#external-events-listing' ).text( event.title );
el.draggable({
zIndex: 999,
revert: true,
revertDuration: 0
});
el.data('event', { title: event.title, id :event.id, stick: true });
}
}
});
calendar.render();
let isEventOverDiv = function(x, y) {
var external_events = $( '#external-events' );
var offset = external_events.offset();
offset.right = external_events.width() + offset.left;
offset.bottom = external_events.height() + offset.top;
// Compare
if (x >= offset.left
&& y >= offset.top
&& x <= offset.right
&& y <= offset .bottom) { return true; }
return false;
}
});
I figured out that the jsEvent is now located in event.jsEvent. This is where I can get the position from now.

fullcalendar eventDragStop triggered after event returns to original position

I would like to delete events on a fullcalendar jquery plugin by dragging them to a trash can image and dropping them in. There are several posts that discuss this action but I can't seem to get mine to work.
The trash can image is defined in the cshtml below:
<div class="well well-sm" id="deleteEventsDiv" style="text-align:center">
<label id="delete_events_lbl" style="display:block; text-align:center; font-size:medium; font-weight:bold">Delete Events</label>
<img src="~/Images/cal-trash.png">
<div class="note">
<strong>Note:</strong> Drag and drop events here to delete them
</div>
</div>
I can drag the event to the trash can but it reverts back to its original position then the eventDragStop event is triggered. Since it is not over the trash can, the rest of the code is not run. This is my fullcalendar code:
$('#edit_calendar').fullCalendar({
header:
{
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
titleFormat: { month: 'MMMM' },
defaultView: 'month',
selectable: true,
selectHelper: true,
droppable: true,
drop: function (date, jsEvent, ui, resourceId) {
var memberName = $(this).data('event').title;
var memberID = $(this).attr('id').toString();
//Create Event - add to array
var newEvent = new Object();
newEvent = {
title: memberName,
id: memberID,
start: date.format(),
end: date.format(),
objectID: 0
};
eventsAdded.push(newEvent);
},
editable: true,
//The following constraints prevents the user from adding/updating/deleting events that are before the current date
//The end date is required. So, you can't add events over a year away from the current date
eventConstraint: {
start: moment().startOf('day'),
end: moment(moment().startOf('day'), 'MM-DD-YYY').add('days', 365)
},
selectConstraint: {
start: moment().startOf('day'),
end: moment(moment().startOf('day'), 'MM-DD-YYY').add('days', 365)
},
resizable: true,
dragRevertDuration: 0,
eventDragStop: function (event, jsEvent, ui, view) {
alert('event drag stopped...should be over trash can.');
// This condition makes it easier to test if the event is over the trash can using Jquery
if ($('div#deleteEventsDiv').is(':hover')) {
// Confirmation popup
$.SmartMessageBox({
title: "Delete Event?",
content: 'Are you sure you want to remove this event from the calender?',
buttons: '[No][Yes]'
}, function (ButtonPressed) {
if (ButtonPressed === "Yes") {
// You can change the URL and other details to your liking.
// On success a small box notification will fire
$.ajax({
url: '/events/' + event.id,
type: 'DELETE',
success: function (request) {
$.smallBox({
title: "Deleting Event",
content: "Event Deleted",
color: "#659265",
iconSmall: "fa fa-check fa-2x fadeInRight animated",
timeout: 4000
});
$('#edit_calendar').fullCalendar('removeEvents', event.id);
}
});
}
});
}
}
}); //end calendar initialization
How do I get the event from NOT returning to its original position when it is over the trash can?
i had same problem here. And i found a paleative solution.
I hope that it works for you too.
Open fullcalendar.js and edit:
dragRevertDuration: 500
to
dragRevertDuration: 0

Adding/Removing eventSources FullCalendar

I'd like to be able to filter events based on adding and removing eventSources. I can't find a good example of this being done.
.fullCalendar( 'addEventSource', source )
.fullCalendar( 'removeEventSource', source )
I'd like to have check boxes that toggle the execution of those functions. I can't seem to get the functionality working though.
$( "#target" ).click(function() {
$('#calendar').fullCalendar( 'removeEventSource', 'Event1' );
});
Here is my full code:
$('#calendar').fullCalendar({
header: {
left: 'title',
center: 'prev,next',
right: 'month,agendaWeek,agendaDay,today'
},
eventLimit: {
'agenda': 4, // adjust to 6 only for agendaWeek/agendaDay
'default': true // give the default value to other views
},
eventSources: [
{
title: 'Event1',
url: "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic"
},
{
url: 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'
},
{
url: "https://www.google.com/calendar/feeds/ht3jlfaac5lfd6263ulfh4tql8%40group.calendar.google.com/public/basic"
}
],
eventClick: function(event) {
// opens events in a popup window
window.open(event.url, 'gcalevent', 'width=700,height=600');
return false;
},
loading: function(bool) {
if (bool) {
$('#loading').show();
}else{
$('#loading').hide();
}
}
});
Here is the full code I used to get this functionality:
HTML:
<form id="#calendar_list">
<input class="checkbox" type="checkbox" checked>Event Group 1<br>
<input class="checkbox1" type="checkbox" checked>Event Group 2<br>
<input class="checkbox2" type="checkbox" checked>Event Group 3<br>
</form>
Javascript:
$(".checkbox").change(function() {
if(this.checked) {
$('#calendar').fullCalendar( 'addEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
}
else{
$('#calendar').fullCalendar( 'removeEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
}
});
Load FullCalendar : Use following given code to load FullCalendar. create a jquery function like LoadCalendar and put below code in this function and call this function on document.ready function in jquery.
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
locale: '#companyCulture',
defaultDate: Date.now(),
defaultView: 'month',
navLinks: true, // can click day/week names to navigate views
editable: false,
eventLimit: true, // allow "more" link when too many events
dayClick: function (date, allDay, jsEvent, view) {
//$("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm") + '');
$("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm A") + '');
$("#hdRDate").val(moment(date).format());
emptyEventDetails(date);
// $("#AddEventModel").modal();
},
eventClick: function (calEvent, jsEvent, view) {
$.ajax({
type: "GET",
async: false,
cache: false,
url: "#Url.Action("GetEventById", "Events")",
data: {
Eventid: calEvent.id
},
success: function (data) {
emptyEventDetails();
//$.each(data.data, function () {
// alert(this["Title"]);
// var color = 'orange';
// var Title = this["Title"];
// //addCalanderEvent(this["EventID"], this["EventDate"], Title, color);
//});
}
});
//$("#lblDate").html('' + calEvent.EventDate + '');
//$("#hdRDate").val(calEvent.EventDate);
//$("#AddEventModel").modal();
}
});
Add a Event: Use the below code to add a event in FullCalendar
var eventObject = {
title: title,
start: moment(start).format("MMMM DD,YYYY hh:mm A"),
end: moment(end).format("MMMM DD,YYYY hh:mm A"),
id: id,
color: colour
};
$('#calendar').fullCalendar('renderEvent', eventObject, true);
OR
$('#calendar').fullCalendar( 'addEventSource', newSource); //Add a new source
Remove all Events: I'm trying to remove all the event sources in the fullcalendar plugin. I'm currently using a combination of
$('#calendar').fullCalendar('removeEvents') //Hide all events
$('#calendar').fullCalendar('removeEventSource', $('.Source').val()) //remove eventSource from stored hidden input
OR
$('#Calendar').fullCalendar( 'removeEvents').fullCalendar('removeEventSources'); //Removes all event sources

Fetching all GoogleCalendar Events before FullCalendar has loaded

I currently am using Adam Shaw's jQuery Calendar 'FullCalendar' and am experiencing significant delays in the calendar rendering. In short, the page appears, 1 second passes, the Calendar pops in, another second passes, and then the events populate the page, here. Is there a way to only fetch a certain number of events behind and before today's date? Or even loading the calendar immediately would be an improvement. I am also using Craig Thompson's qTip2.
Javascript
<script type=text/javascript>
// Setup FullCalendar
jQuery(document).ready
(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var tooltip = $('<div/>').qtip({
id: 'fullcalendar',
prerender: true,
content: {
text: ' ',
title: {
},
},
events: {
render: function(event, api) {
var elem = api.elements.bgiframe;
}
},
position: {
my: 'bottom center',
at: 'top center',
target: 'event',
viewport: $(window),
adjust: {
mouse: false,
scroll: true,
method: 'shift',
resize: true
}
},
show: {
modal: {
on: false,
blur: true,
stealfocus: false
}
},
hide: false,
style: 'qtip-bootstrap'
}).qtip('api');
$('#fullcalendar').fullCalendar({
eventSources: ["https://www.google.com/calendar/feeds/emailaddresshere/public/basic",
"http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic"],
header: {
left: 'title',
center: '',
right: 'today prev,next'
},
selectable: true,
eventClick: function(data, event, view) {
var content = '<h3>'+data.title+'</h3>' +
'<p><b>Start:</b> '+data.start+'<br />' +
(data.end && '<p><b>End:</b> '+data.end+'</p>' || '');
tooltip.set({
'content.text': content
})
.reposition(event).show(event);
},
dayClick: function() { tooltip.hide() },
eventResizeStart: true,
eventDragStart: false,
viewDisplay: function() { tooltip.hide() }
});
}());
</script>

Display only allDay events in a month view full calendar

How to display only allDay = true events in full calendar month view , and remaining non all Day events as usal in other views
You can do this by checking for view.name in a callback like eventRender. Take a look at this fiddle: http://jsfiddle.net/100thGear/vyKSZ/
Hope this helps!
$('#external-events div.external-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 1111999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventDrop: function(event, delta, revertFunc) {
alert( event.id );
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}/task/periodic-task-update",
data : {
id : event.id ,
date :event.start.format()
},
success: function(data) {
if(data=='Task Period Succesfully Changed'){
toastr.success("Task Period Succesfully Changed.");
}else{
toastr.success("Something Wrong");
revertFunc();
}
},
error: function(data,textStatus,xhr) {
toastr.success("Something Wrong");
revertFunc();
}
});
},
events: [
<c:forEach var='periodicTask' items='${periodicTaskTemplates}'>
<c:forEach varStatus="i" begin = "1" end = "12">
{ id: '${periodicTask.id}', title: '${periodicTask.task}', start: new Date(y, '${i.index}', '${periodicTask.startDate}'), end: new Date(y, '${i.index}', '${periodicTask.lastDate}') ,type:'${periodicTask.description}',location:'${periodicTask.location.name}'},
</c:forEach>
</c:forEach>`
],
});

Resources