Error when registering Fullcalendar event

Asked

Viewed 508 times

0

I am facing a small problem with the Fullcalendar plugin, the following is happening.

When I click on a date to record 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 the one saved with the data saved on the date I had previously clicked.

I have tried to remove the Ubmit event from within the 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 could help me, I’d appreciate it. 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();
		});

  • Post important parts of your code. You can read that and then edit the question.

  • This is my code, I do not understand why he sends the two dates clicked for my events.php. ai is giving error why he registers the previous date I clicked and saves another blank record on the date that was to be recorded

  • He is all commented on why I am doing tests and when I give the console.log to see what returns from the events in the variable start that is the start date back to the two dates clicked

  • Try to take the Submit event from the form inside the select callback. Just leave the modal opening inside

  • Check out this link http://jamelbaz.com/tutos/integration-de-fullcalendar2-php-mysql

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.