Event is deleted when clicking cancel in Lightbox


A newly added event is saved to a database via a webservice. When clicking on the new event the lightbox opens but when I click cancel my event gets deleted. My code is to long to paste here so I’ve attached it: my script.7z (2.68 KB). Also, is there a way to limit the number of events one can added? I would like to limit it ot one. I’m using the scheduler as a reservation tool and visitors should only be able to make one reservation.

Best regards, Sven


  1. When you create an event with doubleclick and the lightbox is opened for configuring this event - scheduler sets inner flag which indicates that lightbox is triggered for creating the event. If user press ‘cancel’ and scheduler detects that lightbox was opened with this flag, cancel means that event creation should be canceled (i.e. temporary displayed event should be removed).

Probably something in your code breaks the expected action flow, and ‘new event’ flag never gets cleaned. That could cause an events to be deleted each time user press cancel.

Try following:
use scheduler.hide_lightbox()
or scheduler.endLightbox(false/true);

In order to hide the lightbox.

Try returning ‘true’ from onEventSave handler, that will hide the lightbox and set all required flags.

I can’t give more precise recomendations, since only js is not enough to try the demo locally.

  1. You may detect if user has created and event, and block event creating after that:

scheduler.config.dblclick_create = false; scheduler.attachEvent("onBeforeEventCreated", function (e){ if( ! can add event ) return false; return true; });
docs.dhtmlx.com/scheduler/api__s … event.html
docs.dhtmlx.com/scheduler/api__s … onfig.html

Thanks, you solution worked! I’ve added sched.endLightBox(true); in the onEventSave event and now cancelling works.

I now have a problem that after a move or drag of an event, it is hidden (not deleted) after the onEventChanged event is excecuted. The event I attach looks like this:

sched.attachEvent(“onEventChanged”, function (id, ev) {
ReservationFunction(sched, id, ev, “update_reservation”);
var state = sched.getState();
if (state.lightbox_id != null)

the code of ReservationFunction strigifies dates of the scheduler event. The component expects start/end dates to be a JS Date object, so after you replace them with strings it can no longer work with that event. Try working with a copies of scheduler events instead of modifying the original ones:function ReservationFunction(scheduler, id, ev, whatFunction) { if (ev) { ev.start_date = ev.start_date.toLocaleString(); ev.end_date = ev.end_date.toLocaleString(); }

function ReservationFunction(scheduler, id, ev, whatFunction) { var ev = $.extend({}, ev); if (ev) { ev.start_date = ev.start_date.toLocaleString(); ev.end_date = ev.end_date.toLocaleString(); }