fires before a new link is added to the Gantt chart

boolean onBeforeLinkAdd(string|number id,object link);
idstring|numberthe link id
linkobjectthe link object
booleandefines whether the default action of the event will be triggered (true) or canceled (false)


gantt.attachEvent("onBeforeLinkAdd", function(id,link){
    //any custom logic here
    return true;


The event is blockable. Return false to cancel adding of the link.

//excludes overtaking the target task by the source task
//in case of creating "finish_to_start" links
gantt.attachEvent("onBeforeLinkAdd", function(id, link){
    if (link.type == 0){
        var sourceTask = gantt.getTask(link.source);
        var targetTask = gantt.getTask(link.target);
        if (sourceTask.end_date >= targetTask.start_date){
            alert("This link is illegal")
            return false;
See also
Back to top