Block adding into undo stack on before task update

Hello. We have an undo functionality in gantt. We need to show the user a confirmation dialog on drag or resize of task before we apply the updates. However, the onBeforeTaskChanged is not asynchronous and the dialog is async so the task is updated before confirmation and added in the undo stack.

gantt.attachEvent('onBeforeTaskChanged', function (id: string, mode: string, origTask: Task) {
    if (
      (newTask.startable_date && newTask.start_date! > newTask.startable_date)) {

      showConfirmMessage('Are you sure?').then((confirm) => {
        if (!confirm) {
          newTask = origTask;
          gantt.updateTask(id, newTask);
        } else {
          return true;
        }
      });
    }

    return true;
  });

Hello Cairo,
If you want to show a confirm box, you need to return false at the end of the function regardless of the user response. Then, if the user agrees with the changes, you need to update the task with the Gantt API.
When you return false, the original task dates are restored, so, you cannot get them in the callback function (or the function you use in your application). So, you need to make a deep copy of the task object by using the copy method:
https://docs.dhtmlx.com/gantt/api__gantt_copy.html

The easiest way to update the task object is to use the mixin method and specify true as the 3rd argument to overwrite the changes:
https://docs.dhtmlx.com/gantt/api__gantt_mixin.html

Here is an example of how it can be implemented:
https://snippet.dhtmlx.com/v5iut9cl

Hi Ramil,

Thank you for the response. It somehow blocks the task update, but the parent projects remain drawn on the new dates and it didn’t revert when the user click ‘No’.

Sorry. Please disregard.
I just put the gantt.refreshData() inside the else block.