Cancelling a reopened Lightbox leaves new event on Scheduler

Hello,

I am having some trouble regarding Custom Lightboxes.

What I want to do is:

  1. If the DataAction returned via the Save action is of the type “error”, display the error message in an alert window
  2. When the user closes the alert window, re-open the Lightbox so they can fix the error and save again, or just cancel

The issue I am facing is as follows:

  • When the user creates an event and clicks “Cancel” before clicking “Save”, the event is deleted from the Scheduler - this is good
  • When the user creates an event and clicks “Save”, the server returns an error, which is displayed in an alert window, and the Lightbox re-opens. If they then click “Cancel”, the event remains on the Schedule - I need it to be deleted, the same as if they had never clicked “Save”

To re-open the Lightbox, I use the following:

function postInit() {
	var restoreLightbox = false;
	scheduler.dataProcessor.attachEvent("onAfterUpdate", function (event_id, action, new_event_id, response) {
		if (action == "error") {
			restoreLightbox = event_id;
			dhtmlx.message({
				title: "Error",
				type: "alert-error",
				text: response.text || response.textContent,
				callback: function () {
					if (restoreLightbox) {
						scheduler.showLightbox(restoreLightbox);
						restoreLightbox = false;
					}
				}
			});
		}
	});
}

This method is assigned to the Scheduler via:

sched.AfterInit.Add("postInit();");

I set my custom form as the Lightbox via:

sched.Lightbox.SetExternalLightboxForm(...);

I am fairly new to using this control, so I imagine I am missing something fairly simple. Any help would be greatly appreciated.

Thank you.

Hello,
it looks like a bug of custom lightbox module. A value of the flag that tells that event is being created and should be removed if user close the lightbox without saving is lost after server returns error response.
We’ll investigate the issue from our side, as for now - try setting that flag value manually (you’ll need to use an internal property for that). Here is the code:

[code]function postInit() {
var restoreLightbox = false;
scheduler.dataProcessor.attachEvent(“onAfterUpdate”, function (event_id, action, new_event_id, response) {
if (action == “error”) {

     // !!!
     var newEvent = scheduler._new_event;

     restoreLightbox = event_id;
     dhtmlx.message({
        title: "Error",
        type: "alert-error",
        text: response.text || response.textContent,
        callback: function () {
           if (restoreLightbox) {

              //!!!
              scheduler._new_event = newEvent;

              scheduler.showLightbox(restoreLightbox);
              restoreLightbox = false;
           }
        }
     });
  }

});
}[/code]

Hello, thanks for the reply Aliaksandr

Your workaround has put me on the right path - scheduler._new_event appears to be null in “onAfterUpdate”, so I instead set it in “onBeforeUpdate” like so:

var newEvent = null;
scheduler.dataProcessor.attachEvent("onBeforeUpdate", function (id, state, data) {
	newEvent = scheduler._new_event;
	return true;
});

The new event is now being deleted when cancelling after receiving an error, exactly what I was after.

Thank you very much for the help.