Full Calendar Example with Client Side Edits

FullCalendar Example with Client-Side Event Updates

Hey everyone,

I’ve been mucking around with FullCalendar recently and decided to share one of the prototypes I’ve ended up with. It basically lets the user change the events without having to do a postback. A user simply has to click the event, type in the changes and hit update.

I’ve posted the code below, however there’s also a zip which is a little easier to manage. Note that you’ll probably want to clean it up a little if you plan to use it in production. The following libraries and plugins are also used:
jQuery UI
jQuery FullCalendar
jQuery miniColors

What it Looks Like:

Full Calendar Example with Client Side Edits

Full Calendar Example with Client Side Edits

How to Use It:

It’s all pretty straight forward, but just in case any one runs into issues there are two parts to this example. First, you generate an event template. You can then drag and drop this template onto the calendar as many times as you want.

The second part allows you to edit existing events without posting back to the server. To do this, simply click an event and then make the necessary adjustments using the top panel on the right. Once you’re done, just press update event.

The example uses the standard title property, but also includes a few others: descriptions, price, available. You can change/remove these to suit your needs, just remember to pull them out of the JavaScript as well.


Full Calendar Zip

Basic Example Page:

  1. <html>
  2. 	<head>
  4. 		<!-- Stylesheets etc -->
  5. 		<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.9.2.custom.css" />
  6. 		<link rel="stylesheet" type="text/css" href="css/fullcalendar.css" />
  7. 		<link rel="stylesheet" type="text/css" href="css/view_calendar.css" />
  8. 		<link rel="stylesheet" type="text/css" href="css/jquery.miniColors.css" />
  9. 	</head>
  10. 	<body>
  12. 		<!-- Content Wrapper -->
  13. 		<div id="content_wrapper">
  15. 			<!-- Calendar div -->
  16. 			<div id="calendar">
  17. 			</div>
  19. 			<!-- Event generation -->
  20. 			<div id="event_generation_wrapper">
  21. 				<div class='left'>
  22. 					<div class='text'>Background:</div><br /> 	
  23. 					<div class='text'>Border:</div><br />
  24. 					<div class='text'>Text:</div><br />	
  25. 				</div>
  26. 				<div class='right'>
  27. 					<input id="txt_background_color" type='hidden' class='color_picker' value='#2795C3' /><br />
  28. 					<input id="txt_border_color" type='hidden' class='color_picker' value='#6AB3D3' /><br />
  29. 					<input id="txt_text_color" type='hidden' class='color_picker' value='#ffffff' /><br />
  30. 				</div>
  31. 				<input id='txt_title' type='text' value='Title' /><br />
  32. 				<textarea id='txt_description'>Description</textarea><br />
  33. 				<input id='txt_price' type='text' value='5.00' /><br />
  34. 				<input id='txt_available' type='text' value='5' /><br />
  35. 				<input id="btn_gen_event" type="button" value="New Template" class='btn' />
  36. 				<input id="btn_update_event" type="button" value="Update Event" class='btn'/>
  37. 				<input id="txt_current_event" type="hidden" value="" />
  38. 			</div>
  40. 			<!-- Booking types list -->
  41. 			<div id='external_events'>
  42. 				<div id='external_event_template' class='external-event ui-draggable'>One Hour</div>
  43. 			</div>
  44. 		</div>
  46. 		<!-- Include scripts at bottom to aid dom loading and prevent hangs -->
  47. 		<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
  48. 		<script type='text/javascript' src='js/jquery-ui-1.9.2.custom.min.js'></script>
  49. 		<script type='text/javascript' src='js/fullcalendar.js'></script>
  50. 		<script type='text/javascript' src='js/view_calendar.js'></script>
  51. 		<script type='text/javascript' src='js/jquery.miniColors.js'></script>
  52. 	</body>
  53. </html>

Basic JavaScript:

/* Wait for DOM to load etc */
/* Initialise buttons */
function initialise_buttons(){
/* Binds and initialises event generation functionality */
function initialise_event_generation(){
	//Bind event
	$('#btn_gen_event').bind('click', function(){
		//Retrieve template event
		var template_event = $('#external_event_template').clone();
		var background_color = $('#txt_background_color').val();
		var border_color = $('#txt_border_color').val();
		var text_color = $('#txt_text_color').val();
		var title = $('#txt_title').val();
		var description = $('#txt_description').val();
		var price = $('#txt_price').val(); 
		var available = $('#txt_available').val();
		//Edit id
		$(template_event).attr('id', get_uni_id());
		//Add template data attributes
		$(template_event).attr('data-background', background_color);
		$(template_event).attr('data-border', border_color);
		$(template_event).attr('data-text', text_color);
		$(template_event).attr('data-title', title);
		$(template_event).attr('data-description', description);
		$(template_event).attr('data-price', price);
		$(template_event).attr('data-available', available);
		//Style external event
		$(template_event).css('background-color', background_color);
		$(template_event).css('border-color', border_color);
		$(template_event).css('color', text_color);
		//Set text of external event
		//Append to external events container
		//Initialise external event
		initialise_external_event('#' + $(template_event).attr('id'));
/* Initialise external events */
function initialise_external_event(selector){
	//Initialise booking types
		//Make draggable
			revert: true,
			revertDuration: 0,
			zIndex: 999,
			cursorAt: {
				left: 10,
				top: 1
		//Create event object
		var event_object = {
			title: $.trim($(this).text())
		//Store event in dom to be accessed later
		$(this).data('eventObject', event_object);
/* Initialise color pickers */
function initialise_color_pickers(){
	//Initialise color pickers
		'trigger': 'show',
		'opacity': 'none'
/* Initialises calendar */
function initialise_calendar(){
	//Initialise calendar
		theme: true,
		firstDay: 1,
		header: {
			left: 'today prev,next',
			center: 'title',
			right: 'month,agendaWeek,agendaDay'
		defaultView: 'agendaWeek',
		minTime: '6:00am',
		maxTime: '6:00pm',
		allDaySlot: false,
		columnFormat: {
			month: 'ddd',
			week: 'ddd dd/MM',
			day: 'dddd M/d'
		eventSources: [
				url: 'calendar_events.json',
				editable: false
		droppable: true,
		drop: function(date, all_day){
			external_event_dropped(date, all_day, this);
		eventClick: function(cal_event, js_event, view){
			calendar_event_clicked(cal_event, js_event, view);
		editable: true
	//Initialise external events
/* Handle an external event that has been dropped on the calendar */
function external_event_dropped(date, all_day, external_event){
	//Create vars
	var event_object;
	var copied_event_object;
	var duration = 60;
	var cost;
	//Retrive dropped elemetns stored event object
	event_object = $(external_event).data('eventObject');
	//Copy so that multiple events don't reference same object
	copied_event_object = $.extend({}, event_object);
	//Assign reported start and end dates
	copied_event_object.start = date;
	copied_event_object.end = new Date(date.getTime() + duration * 60000);
	copied_event_object.allDay = all_day;
	//Assign colors etc
	copied_event_object.backgroundColor = $(external_event).data('background');
	copied_event_object.textColor = $(external_event).data('text');
	copied_event_object.borderColor = $(external_event).data('border');
	//Assign text, price, etc
	copied_event_object.id = get_uni_id();
	copied_event_object.title = $(external_event).data('title');
	copied_event_object.description = $(external_event).data('description');
	copied_event_object.price = $(external_event).data('price');
	copied_event_object.available = $(external_event).data('available');
	//Render event on calendar
	$('#calendar').fullCalendar('renderEvent', copied_event_object, true);
/* Initialise event clicks */
function calendar_event_clicked(cal_event, js_event, view){
	//Set generation values
	set_event_generation_values(cal_event.id, cal_event.backgroundColor, cal_event.borderColor, cal_event.textColor, cal_event.title, cal_event.description, cal_event.price, cal_event.available);
/* Set event generation values */
function set_event_generation_values(event_id, bg_color, border_color, text_color, title, description, price, available){
	//Set values
	$('#txt_background_color').miniColors('value', bg_color);
	$('#txt_border_color').miniColors('value', border_color);
	$('#txt_text_color').miniColors('value', text_color);
/* Generate unique id */
function get_uni_id(){
	//Generate unique id
	return new Date().getTime() + Math.floor(Math.random()) * 500;
/* Initialise update event button */
function initialise_update_event(){
	var test = $('#calendar').fullCalendar( 'clientEvents');
	//Bind event
	$('#btn_update_event').bind('click', function(){
		//Create vars
		var current_event_id = $('#txt_current_event').val();
		//Check if value found
			//Retrieve current event
			var current_event = $('#calendar').fullCalendar('clientEvents', current_event_id);
			//Check if found
			if(current_event && current_event.length == 1){
				//Retrieve current event from array
				current_event = current_event[0];
				//Set values
				current_event.backgroundColor = $('#txt_background_color').val();
				current_event.textColor = $('#txt_text_color').val();
				current_event.borderColor = $('#txt_border_color').val();
				current_event.title = $('#txt_title').val();
				current_event.description = $('#txt_description').val();
				current_event.price = $('#txt_price').val();
				current_event.available = $('#txt_available').val();
				//Update event
				$('#calendar').fullCalendar('updateEvent', current_event);


  1. body{
  2. 	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  3. 	font-size: 12px;
  4. }
  6. #content_wrapper{
  7. 	width: 820px;
  8. 	margin-left: auto;
  9. 	margin-right: auto;
  10. }
  12. #calendar{
  13. 	width: 650px;
  14. 	float: left;
  15. }
  17. .btn{
  18. 	font-size: 85%
  19. 	margin-top: 10px;
  20. }
  22. #event_generation_wrapper{
  23. 	float: left;
  24. 	width: 120px;
  25. 	background-color: #DDD;
  26. 	margin-left: 20px;
  27. 	margin-top: 40px;
  28. 	border: 1px solid #4297D7;
  29. 	background-color: #FCFDFD;	
  30. 	-moz-border-radius: 3px;
  31. 	-webkit-border-radius: 3px;
  32. 	border-radius: 3px;
  33. 	padding: 10px 5px 10px 5px;
  34. }
  36. #event_generation_wrapper .left{
  37. 	float: left;
  38. 	width: 70px;
  39. }
  41. #event_generation_wrapper .right{
  42. 	float: left;
  43. 	max-width: 25px;
  44. 	margin-left: 10px;
  45. }
  47. #event_generation_wrapper input{
  48. 	width: 112px;
  49. }
  51. #event_generation_wrapper textarea{
  52. 	width: 110px;	
  53. 	height: 50px;
  54. }
  56. #event_generation_wrapper .miniColors-triggerWrap{	
  57. 	margin-bottom: 5px;
  58. }
  60. #event_generation_wrapper .text{
  61. 	padding-top: 1px;	
  62. 	margin-bottom: 5px;
  63. 	line-height: 10px;
  64. }
  67. #external_events{
  68. 	float: left;
  69. 	width: 130px;
  70. 	background-color: #DDD;
  71. 	margin-left: 20px;
  72. 	margin-top: 40px;
  73. 	border: 1px solid #4297D7;
  74. 	background-color: #FCFDFD;	
  75. 	-moz-border-radius: 3px;
  76. 	-webkit-border-radius: 3px;
  77. 	border-radius: 3px;
  78. }
  80. #external_events .external-event{
  81. 	width: 100px;
  82. 	margin: 5px;
  83. 	font-family: Verdana, Arial, sans-serif;
  84. 	border: 1px solid #36C;
  85. 	padding: 3px;
  86. 	text-align: center;
  87. 	background-color: #36C;
  88. 	color: white;
  89. 	cursor: pointer;
  90. 	-moz-border-radius: 3px;
  91. 	-webkit-border-radius: 3px;
  92. 	border-radius: 3px;
  93. }
  95. #calendar .ui-widget-header{
  96. 	font-weight: normal;
  97. 	padding: 3px 3px 3px 3px;
  98. }
  100. #calendar .fc-header-title{
  101. 	font-weight: normal;
  102. }
  104. #external_event_template{
  105. 	display: none;
  106. }

Basic List of Events (JSON):

  1. [
  2.     "0",
  3.     {
  4.         "allDay": "",
  5.         "title": "Test event",
  6.         "id": "821",
  7.         "start": "2012-11-23 14:00:00",
  8.         "end": "2012-11-23 15:00:00"        
  9.     },
  10.     "1",
  11.     {
  12.         "allDay": "",
  13.         "title": "Test event 2",
  14.         "id": "822",        
  15.         "start": "2012-11-23 9:00:00",
  16.         "end": "2012-11-23 10:00:00"
  17.     },
  18.     "2",
  19.     {
  20.         "allDay": "",
  21.         "title": "Test event 3",
  22.         "id": "823",        
  23.         "start": "2012-11-24 8:00:00",
  24.         "end": "2012-11-24 6:00:00"
  25.     },
  26.     "3",
  27.     {
  28.         "allDay": "",
  29.         "title": "Test event 4",
  30.         "id": "824",        
  31.         "start": "2012-11-27 6:00:00",
  32.         "end": "2012-11-27 7:00:00"
  33.     }
  34. ]

Let me know if you have any issues or something to add!


40 thoughts on “FullCalendar Example with Client-Side Event Updates

  1. Raül

    How to do that the events persist? I mean, I create new events, they are shown but when I go out and back (refresh page, go out anb back to the site, etc) they are disappeared.

    1. Chris Owens Post author

      Hey Raul,

      To store the events you’ll probably want to wire it up to a backend of some sort or look into HTML5 storage depending on what you’re after. Alternatively, FullCalendar does support Google Calendar. I haven’t tried it but if it’s probably a lot quicker to setup if you don’t need a fully fledged app. Check out this link for more info: http://arshaw.com/fullcalendar/docs/google_calendar/.

  2. Kala Kala

    Nice ! How to remove the event just dropped from the event list (i want to be able to drop an event only once). Can we reverse an event to the events list ?

    Thanks you and sorry for my english

    1. Chris Owens Post author

      Hey Kala,

      No worries. If I’m understanding you right, all you’d need to do is an a line to the external_event_dropped event. Just remove the matching template from the id. You might be better off redoing the event list if you’re going to do much with it though, this is really just a mock-up. If I were to do it all again, I’d probably take a look at AngularJS – you could do some really nice stuff wiring this up as a directive.

      Let me know if you need any more info.


  3. James Klein

    I’m using FullCalendar out of the box following their documentation. I’m able to pass json to the view with my Event’s controller with no problem but I can’t seem to do an ajax post request as a PUT to update the event after moving it around the calendar.
    I’m getting this message
    > PUT http://localhost:3001/events/2 406 (Not Acceptable)

    and the code that I’ve dropped into my calendar.js is as follows
    editable: true,
    eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
    url: “/events/”+event.id
    I know I’m not passing any data right now but I just want to get the post working.
    Thanks in advance and any help is appreciated.

    1. Chris Owens Post author

      Hey James,

      I’m going to need some more info to be able to help, this is probably server side.

      Is it just put that’s affected or is post being rejected as well? What stack etc?

      If you can you provide a link or fiddle I’ll take a quick look? Might also be worth trying to set to set the content type.


      1. James Klein

        Hey Chris,
        I meant to reply to this awhile ago. Not sure what the fix was back then but here is my updated code incase it helps anyone else. Notice the “.json” which may have been the problem.

        eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
        url: “/events/” + event.id +”.json”,
        type: ‘PUT’,
        data: { days_moved: dayDelta },
        success: function(result) {
        error: function() {
        console.log(“Failed to update event”);


  4. Karteek Kommana

    Hi Chris,
    It was nice work for fullCalendar. I appreciate your work. I wonder is it possible to save the events in Database and show it agian when ever the web page is loaded? I want to have a event calendar in my project where user can able to create event and see it when ever they visit the page again.

  5. Lugisani Muthige

    There seems to a bug on the calendar interface, when i navigate through dates there is a blue portion that comes up from the buttons to the date title, its like one that’s meant for editing the date i’m not sure… and when i add events on the monthly view they don’t appear on the week and day view.

  6. Gary

    Chris, just want to say thanks, this is an excellent foundation and starting point, thanks for the framework to get up and running with understanding of how to implement and tool the calendar.

  7. Gary

    Chris, one more thing, wondering if you’ve encountered this in your work with this but is there an easy way to incorporate the repeat event, say, I want to set an event that I am on call every 3rd week of every month? thanks again

  8. Gary

    Chris, you are differently the master and a very kewl person to keep this up and provide us with your knowledge. a million thanks, because without it, I know I would spend countless hours getting to this point. thank you very much!!

  9. Peter Kaye

    Thanks for this post which has opened my eyes to Full Calendar features I’d not been aware of.

    I’d like to render the event id in the HTML as an HTML ID or similar so that I can pick it up in an Microsoft Access application. For example

    Peter Jones

    where 99023 is the MySQL ID for the event. Is this possible and if so could you point me in the right direction ? Thanks again.

    1. Chris Owens Post author

      Hey Peter,

      Sorry, I’m not too sure what you mean? Do you want to have it appear in the event so that users can can see it, or just have it as a data attribute on the element?


      1. Peter Kaye

        Thanks Chris.
        No I don’t want the id to appear on the calendar, just in the HTML so that my VBA screen scrape can read it and find the correct calendar event record.

  10. Peter Kaye

    I should have realised that HTML gets stripped from WP comments ! The missing code relates to the Full Calendar Div which wraps the event and has a class of fc-event-inner.

  11. Harsh Jhaveri

    Hello, I am using Full Calendar in my pages, but there is some issues as if i am selecting any records then that day selected but if i am click out side of it, then it will be unselect, even if i m click on page scroll then also it unselect my selection.
    IS there any way where we can default selected particular day which we clicked.

    Please advice


  12. Don Martin

    I am interested in retieving events from a file and tried you eventsource with calendar_events.json. I was not able to get it to work. So I downloaded and ran your zip package. Only the first event is displayed. Has the json spec change in the last year?


  13. Cesar

    Hi Chris , I have a doubt , was reviewing your contribution and I feel sensational, I have just one question , and I take several days looking for information about it and I can not take this, I need you to keep an event that remains assigned a color but not I have idea how to pass this parameter by Jason respect for me to load data into the full calendar from a MySQL DB can be done ?

    Thank You



  14. Jesùs

    Hi Chris,

    You definitely saved one poor soul today from getting insane :)
    Just one remark:
    your function get_uni_id() returns the UNIX timestamp in milliseconds,
    because Math.floor(Math.random()) always equals 0,
    but hey, I guess that return value is unique enough.


  15. Jalaal Charaf

    Hi Chris,

    Really a useful bit of coding. Nice work!

    I cannot get it to work with the newer version of fullcalendar though. Have run into many errors. Did anyone do any updates on this code?



    1. Chris Owens Post author

      Hey Jamie,

      Thanks for the reply hey, unfortunately this was all done on the original fullcalendar. I’m not too sure what’s changed with the updates. I’d tags a look but I’m overseas for a few weeks.

      Please let me know if there’s anything that needs to be added to the party and I’m update it.


  16. Maite Lopez

    Good project. I have two question,

    1.- I don´t see in your code where you say that de time and the content have different color (time darker than content). can you help me to find them?
    2.- I need my date and border in one color (read from DB) and the content in another color (also read from DB). Do you know if it si possible??


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.