dhtmlxdhtmlx-scheduler

'onEventDeleted' trigger when click on cancel button on the event editor


Im using DHTMLX scheduler and I'm trying to delete an event when click on the delete button in the popup event editor, below is my code reference.

scheduler.attachEvent("onEventDeleted", function(id,ev){
    $.ajax({
         url : "calendar.php",
         type: 'post',
         data: { event_id : id},
         success: function(e){
             if($.trim(e) === "success"){
                 alert("Event was successfully deleted");
             }
         }
  });
});

the above code works (The event was deleted successfully) but the problem is, the 'onEventDeleted' did also trigger when i click the cancel button from the popup editor. Any ideas, help, suggestions, recommendations, help please?


Solution

  • It happens only if you press cancel while creating a new event. In this case triggering onEventDeleted is expected since it removes a newly created event from a calendar. In order not to send that update to the backend you can use this method http://docs.dhtmlx.com/scheduler/api__scheduler_getstate.html

    So if you update code like following everything should be good:

    scheduler.attachEvent("onEventDeleted", function(id,ev){
        if(scheduler.getState().new_event)
          return;
    
        $.ajax({
             url : "calendar.php",
             type: 'post',
             data: { event_id : id},
             success: function(e){
                 if($.trim(e) === "success"){
                     alert("Event was successfully deleted");
                 }
             }
      });
    });