Rules when create links
Is there any way to put rules when connecting 2 nodes? For Example: I Have 3 Node X, 3 node Y and 2 node Z, When I try to connect one of the Node X to one of Node Z, show an alert and then deny the connection?
Hello,
Well there is a property for DiagramWidget called allowLooseLinks
<DiagramWidget
className="srd-demo-canvas"
diagramEngine={engine}
allowLooseLinks={false}
/>
This enables code snippet in DiagramWidget Line 353
//check for / remove any loose links in any models which have been moved
353: if (!this.props.allowLooseLinks && this.state.wasMoved) {
If you notice line 379 there is condition:
if (!sourcePort.canLinkToPort(targetPort))
So this means that you have to create own PortModel or inherit from it and override function
canLinkToPort(port: PortModel): boolean {
return true;
}
Notice that you can use port.getParent() to get node and then you can check if nodes can be connected or not. :) hope this will help
Oh, it's easier than I imagined. Thank You very much. I was doing this inside the render() function of the linkWidget (a little of workaround)