Error registering FullCalendar event

0

I'm having a little problem with the FullCalendar plugin, the following is happening.

When I click on a date to save a certain event a modal appears for me to register, but if I leave without saving and click on another day it saves 2 records being one of them blank and what saves with the data saved in date that I had previously clicked.

I have tried to remove the submit event from within function select, but I did not succeed because I need the start and end variables that are the dates to be saved in the database.

If anyone can help me, I thank him from the heart. Thanks in advance

$(document).ready(function() {
			var currentLangCode = 'pt-br';

			// build the language selector's options
			$.each($.fullCalendar.langs, function(langCode) {
				$('#lang-selector').append(
					$('<option/>')
						.attr('value', langCode)
						.prop('selected', langCode == currentLangCode)
						.text(langCode)
				);
			});

			// rerender the calendar when the selected option changes
			$('#lang-selector').on('change', function() {
				if (this.value) {
					currentLangCode = this.value;
					$('#calendar').fullCalendar('destroy');
					renderCalendar();
				}
			});

			function renderCalendar() {
				$('#calendar').fullCalendar({
					header: {
						left: 'prev,next today',
						center: 'title',
						right: 'month,agendaWeek,agendaDay'
					},
					defaultDate: Date(),
					selectable: true,
					selectHelper: true,
					unselectCancel: true,
					select: function(start, end) {
						$("#myModal").modal('show');
						//console.debug(start.format("YYYY-MM-DD HH:mm:ss"));
						//console.debug(end);
						$("#eventForm").on('submit',function() {
							var dados = $(this).serialize();
							$.ajax({
				                type: "POST",
				                url: "eventos.php",
				                data: dados+"&start="+start.format("YYYY-MM-DD HH:mm:ss")+"&end="+end.format("YYYY-MM-DD HH:mm:ss"),
				                //dataType: 'json',
				                success: function( data )
				                {
				                	console.log(data);
				                	/*var eventData;
									if (data.title) {
										if (start.format("hh:mm:ss") == end.format("hh:mm:ss")) {
											eventData = {
												title: data.title,
												start: start.format("YYYY-MM-DD"),
												end: end.format("YYYY-MM-DD"),
												content: data.content
											};
										}else{
											eventData = {
												title: data.title,
												start: start,
												end: end,
												content: data.content
											};
										}
										$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
									}*/
									$('#calendar').fullCalendar('unselect');
				                }
							});
							this.reset();
							$("#myModal").modal("hide");
							return false;
						});
						
					},
					eventClick: function(event) {
						$(this).popover({html:true,title:event.title,placement:'top',container:'body',content: event.content}).popover();
				    },
					lang: currentLangCode,
					buttonIcons: false, // show the prev/next text
					weekNumbers: true,
					editable: false,
					eventLimit: true, // allow "more" link when too many events
					events: {
						url: 'fullcalendar/demos/php/get-events.php',
					},
					loading: function(bool) {
						$('#loading').toggle(bool);
					}
				});
			}

			renderCalendar();
		});
    
asked by anonymous 19.03.2015 / 14:03

0 answers