Task constraints are automatically changing

When I have a constraint on a task, e.g. “snet 1 January”, and I move my task to 7 January, then this should be a valid move. However, the constraint itself also changes.

This behaviour seems to be documented here:

" When a user changes the date of a task by moving it with the mouse pointer or via the lightbox, the task automatically receives one of the two constraint types: either start no earlier than+%start date% or finish no later than+%end date%, depending on the chosen planning strategy."

How do I prevent constraints from changing?

Hello Jonathan,

Yes, as stated in the documentation, when changing the date of a task by moving it with the mouse pointer or via the lightbox, a task automatically updates its constraint type to match the new date (either “Start No Earlier Than” + start date, or “Finish No Later Than” + end date, depending on the planning strategy).

If you want to prevent constraints from changing and keep their original values, you can attach the onBeforeTaskChanged and onLightboxSave events to get full control before saving task changes and preserve the original constraint values:

gantt.attachEvent('onBeforeTaskChanged', function (id, mode, task) {
  setTimeout(function () {
    const modifiedTask = gantt.getTask(id);

    modifiedTask.constraint_type = task.constraint_type;
    modifiedTask.constraint_date = task.constraint_date;
    gantt.updateTask(id);
  }, 10);

  return true;
});

gantt.attachEvent('onLightboxSave', function (originalTaskId, task, is_new) {
  const originalTask = gantt.getTask(originalTaskId);
  const updatedTask = {
    ...task,
    constraint_type: originalTask.constraint_type,
    constraint_date: originalTask.constraint_date,
  };
  gantt.updateTask(originalTaskId, updatedTask);
  return true;
});

Please check an example: DHTMLX Snippet Tool.

Thanks @Valeria_Ivashkevich that helps a lot.