onBeforeLinkAdd

fires before a new link is added to the Gantt chart

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

Example

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

Details

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