How to use temporaryLink in Linktool

Hi,<span =“Apple-tab-span” style=“white-space:pre”> Currently I am using diagram.toolManager.linkingTool.linkValidation to detect whether two nodes can be connected. It worked fine, however I would like to provide better UI gesture to warn users. I searched the forum, this link suggested to use temporaryLink. When and how do I have to set the temporary link to another shape (like from solid line to dash line) to notify the user?

<span =“Apple-tab-span” style=“white-space:pre”> Thanks.

You can define a LinkingBaseTool.portTargeted function to modify the temporaryLink. For example, add this code to the General Linking Validation sample:[code] var invalidDashArray = [4, 4]; // the dash pattern to use when there's no valid port to connect to

diagram.toolManager.linkingTool.portTargeted = function(realnode, realport, tempnode, tempport, toend) { var link = diagram.toolManager.linkingTool.temporaryLink; var shape = link.elt(0); // assume main Shape is the first element if (shape instanceof go.Shape) shape.strokeDashArray = (realport ? null : invalidDashArray); }

diagram.toolManager.relinkingTool.portTargeted = function(realnode, realport, tempnode, tempport, toend) { var link = diagram.toolManager.relinkingTool.temporaryLink; var shape = link.elt(0); // assume main Shape is the first element if (shape instanceof go.Shape) shape.strokeDashArray = (realport ? null : invalidDashArray); }[/code]

Note that the dashedIfInvalid function just works with the LinkingTool