Restrict relinking only to the same node

Hi,

I want to restrict relinking only to other ports on the same node.
So I tried to use link validation:

diagram.toolManager.relinkingTool.linkValidation = function(fromnode, fromport, tonode, toport, link) {
    return tonode == link.toNode;
};

But this only works for the end of a link. For the beginning I should compare fromnode with link.fromNode.
The Problem is: I don’t know which side of the link I am dragging.
Is there a way to get that information?

Thanks in advance.

Querying the LinkingTool’s isForwards property is what you want.

So you’ll want something like this:

diagram.toolManager.relinkingTool.linkValidation = function(fromnode, fromport, tonode, toport, link) {
    if (diagram.toolManager.relinkingTool.isForwards) return tonode == link.toNode;
    return fromnode == link.fromNode;
};

I’m sorry to bother you with my stupidity :slight_smile:
Of course the other side has to stay the same as well because I’m not touching it. So this it the easiest solution:

 return fromnode == link.fromNode && tonode == link.toNode;

Hah, good catch. Definitely a simpler solution.