简体   繁体   中英

FULLCALENDAR V5 format date insert event

I am rewriting my calendar with the latest version of fullcalendar, the problem is that I have to insert events in the database via ajax / json and the start and end variables in javascript give me Invalid date despite being using the new method of formatdate, am I doing something wrong? this is my code:

document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
        var calendar = new FullCalendar.Calendar(calendarEl, {
          initialView: 'dayGridMonth',
          firstDay: 1,
          editable: true,
          headerToolbar: {
            left: 'title',
            center: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek',
            right: 'addEvent,today,prev,next'
          }, // buttons for switching between views
         events: '/sistema/app/config/opt/agenda/load.php',
         selectable:true,
        eventColor: '#378006',
        allDaySlot: true,
        scrollTime :  "08:00:00",
        dayMaxEvents: true,
        allDayText: calendar_lang.allDayText,
        buttonText: calendar_lang.buttonText,
        timeZone: 'local',
        locale: 'it',
        
    customButtons: {
    addEvent: {
      text: 'Evento',
      click: function() {
        var dateStr = prompt('Enter a date in YYYY-MM-DD format');
        var date = new Date(dateStr + 'T00:00:00'); // will be in local time

        if (!isNaN(date.valueOf())) { // valid?
          calendar.addEvent({
            title: 'dynamic event',
            start: date,
            allDay: true
          });
          alert('Great. Now, update your database...');
        } else {
          alert('Invalid date.');
        }
      }
    }
  },
  
select: function(start, end, allDay)
{
console.log(start);
 var start = moment(start, 'DD.MM.YYYY').format('YYYY-MM-DD HH:mm:ss')
 var end = moment(end, 'DD.MM.YYYY').format('YYYY-MM-DD HH:mm:ss')
 var testo = prompt("Enter Event Testo");
 var testo_privato = prompt("Enter Event Testo Privato");
 if(testo || testo_privato)
 {
 var idutente = '<?=$idutente?>';
 var title = '<?=$autore?>';
 var groupcode = '<?=$groupcode?>';
 var tipo = "Annotazione";
 console.log("--------------------------------------");


 console.log(start);
  console.log(end);
      $.ajax({
       url:"/sistema/app/config/opt/agenda/insert.php",
       type:"POST",
       data:{idutente:idutente, title:title, testo:testo, testo_privato:testo_privato, tipo:tipo, start:start, end:end, groupcode:groupcode},
       success:function()
       {
        calendar.refetchEvents();
       }
      })
     }
    },
     });
        calendar.setOption('locale', 'it');
        calendar.render();
        
      });
select: function (date) {
    console.log(date);
    start:date.startStr, end:date.endStr
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM