Task end date is automatically equal to start date if end date is less than start date when I use lightbox.
How to disable this? I don’t want to make automatically this. Because I need to show alert message to users they they have selected wrongly.
Hello Suba,
You need to use the onLightboxSave
event to validate the lightbox values:
https://docs.dhtmlx.com/gantt/api__gantt_onlightboxsave_event.html
https://docs.dhtmlx.com/gantt/desktop__validation.html
You supposed to use the following commands to get the start_date
and end_date
values:
gantt.getLightboxValues();
gantt.getLightboxSection('time').getValue();
But unfortunately, there is a bug, so you will get the wrong end_date
value, and it is still greater than the start_date
:
The dev team will fix it in the future, but I cannot give you any ETA.
As a workaround, you need to obtain the values manually from the DOM elements:
gantt.attachEvent("onLightboxSave", function(id, task, is_new){
var node = gantt.getLightboxSection('time').node;
var date = {day:null, month:null, year:null};
date.day = document.querySelectorAll("select[aria-label='Days']")[1].value;
date.month = document.querySelectorAll("select[aria-label='Months']")[1].value;
date.year = document.querySelectorAll("select[aria-label='Years']")[1].value;
var actual_end_date = new Date(date.year, date.month, date.day)
if (+gantt.getLightboxValues().start_date > +actual_end_date){
gantt.message({type: "error", text: "Correct the start_date"})
return false;
}
return true;
})
The following snippet demonstrates how it works:
http://snippet.dhtmlx.com/5/caf072872
Hello Suba,
The dev team added a way to disable automatic correction of the end date in the time section of the lightbox. To use it, you will need to disable the autofix_end
parameter in the lightbox section configuration:
https://docs.dhtmlx.com/gantt/desktop__time.html
You can check how it works in the following snippet:
http://snippet.dhtmlx.com/5/d77cc79a9