Articles in this section
Category / Section

How to Prevent Multiple Connectors From a Port in JavaScript Diagram?

2 mins read

To prevent a connector from being drawn from a port that already has a connector connected to it in JavaScript Diagram, you can use the elementDraw event. This event is triggered when a connector is being drawn from a port.
By examining the arguments of the event, we can check for existing connections and cancel the drawing if the port is already connected.

Below is an example of how to implement this functionality:

elementDraw: function (args) {
    if (args.state == 'Start') {
      let ports = args.source.ports;
      if (ports && diagram.nodes !== undefined) {
        for (let j = 0; j < ports.length; j++) {
          let port = ports[j];
          if (port && (port.outEdges.length > 0 || port.inEdges.length > 0)) {
            args.cancel = true;
          }
        }
      }
    }
  },

Sample:Click Here

Conclusion

I hope you enjoyed learning how to prevent multiple connectors from a port in JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied