Gojs linkValidation when dragging unconnected link

I’m working on a Diagram with draggable links.

Nodes/Ports and links are typed, i.e. both data objects have a type property, and the properties must match when drawing a new link from one port to another or when (re)connecting a link to a port.

My (re)linkingTool.linkValidation method is as follows:

function sameType(fromnode, fromport, tonode, toport, link) {
    const fromType = fromport ? fromport.panel.data.connector.type : "x";
    const toType = toport ? toport.panel.data.connector.type : "y";
    const linkType = link ? link.data.type : "z";
    return (!link && fromport && toport && fromType === toType)
        || (link && (!fromport || fromType === linkType) && (!toport || toType === linkType));
}

It works great and returns true when a new link is created between ports (fromPort and toPort types match) or when dragging one end of an unconnected link (link and fromPort or toPort types match).

But when an unconnected link is dragged as a whole, neither end will connect to a valid port.
Debugging showed the linkValidation function being called with only fromnode/fromport OR tonode/toport being non-null, whereas the link parameter was always null.

Is this a bug?

Could you try the beta 2.2.11 at https://gojs.net/2.2.11/release/go-debug.js or https://gojs.net/2.2.11/release/go.js ?

looks good!
The “link” parameter is no longer null.

When will this be released?

GoJS 2.2.11 released

1 Like