How to Prevent Deletion of Dependent Connectors in JavaScript Diagram?
In the Syncfusion® JavaScript Diagram component, connectors can be linked to the ports of other connectors. When a connector (acting as a “parent”) is deleted, any connector linked to its ports (i.e., a dependent connector) may also be removed automatically—this is the expected behavior. To prevent this cascading deletion and ensure only the selected connector is removed, you can use the collectionChange event. This event is triggered whenever a node or connector is added, removed, or changed in the diagram. By handling this event, you can implement custom logic to identify and preserve dependent connectors. For example, within the event handler, you can check whether the connector being removed is a dependent one and cancel the removal if needed. Refer to the sample collectionChange event code below:
collectionChange: function(args) {
if (args.element instanceof ej.diagrams.Connector && args.type === "Removal" && args.element.id ==='connector2'){
args.cancel = true
}
}
Kindly refer to the working sample below:
Sample
Conclusion
I hope you enjoyed learning on how to prevent deletion of dependent connectors when deleting a selected connector in JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for 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!