Event Validation - Confirm being ignored

Good day all.

I am having an issue with dhtmlx.confirm being ignored when trying to check if the sections have changed using drag function and lightbox save button.

Here is my code that handles the Drag function.

scheduler.attachEvent(“onBeforeEventChanged”, function(ev, e, is_new, original){

// Quick message to let me know if the logic is working. It does.
dhtmlx.message(ev.section_id != original.section_id);

// Detects a new event and exits properly.
if (is_new){
return true;
}

if (ev.section_id != original.section_id)
{
dhtmlx.confirm(“Are you SURE you want to change the aircraft on a trip that has been published?”);
dhtmlx.message(“This message fires before the confirmation box is confirmed or canceled.”);

// I have used both the long hand and the short hand version of the confirm box. They are ignored.

}
dhtmlx.message(“This message fires before the confirmation box is confirmed or canceled as well.”);
return true; // This return occurs and the data is updated before either of the confirm box buttons are pressed.

});

Thoughts anyone?

Hello @jwood,

There is no good option to "pause the event execution in javascript, so the modal doesn’t do this, it’s expected behavior.

The easiest way to implement what you want is to return “false/true” from the if condition - so it will fire by default. And define the behavior you need in the modal’s callback, so it will fire after you will click the button.

The code may look like this fragment:

var savedEventSection;
var savedEventId;
scheduler.attachEvent("onBeforeEventChanged", function(ev, e, is_new, original){

  if (is_new){
    return true; 
  }

  if (ev.section_id != original.section_id)
  { 
    savedEventSection = ev.section_id;
    savedEventId = ev.id;
    
    var outerResult = dhtmlx.message({
      type:"confirm",
      text: "Are you SURE you want to change the aircraft on a trip that has been published?",
      callback: function(result) {
        if(result){	
          var event = scheduler.getEvent(savedEventId)
          event.section_id = savedEventSection;
          scheduler.addEvent(event)
        } 
        if(!result){
        } 
      }
    });
    return false;
  }
  return true;
}); 

As you can see, the event will return “false” before the modal will fire, but when you will click the “OK” button, the callback will apply the saved data to the event and update it(and send the update to the server).

Here is a demo:
https://snippet.dhtmlx.com/5/253449d95

Here is another option, which looks more native, but will send data to the server twice- before the modal button click, and after it:
http://snippet.dhtmlx.com/5/ea6d1805a