Canceling object addition to the diagram

Hi there,
In case of adding a new connector by user, I do handle the collection change event and when the state is 'Changing' and type is 'Addition', I validate the source and target nodes. If this action is invalid, I set the cancel property of the event arg to cancel the addition, but it dose not work!

I also tried to use remove method of the diagram object, when the state is 'Changed', but it throws an error to the console:
node.js:1621 Uncaught TypeError: Cannot read property 'wrapper' of undefined

please tell me how to cancel an object addition in case of invalid state, thanks

1 Reply

SK Suganthi Karuppannan Syncfusion Team February 24, 2020 09:35 AM UTC

Hi Vahid Rassouli,   
   
While adding the connector at runtime in the diagram, “collectionChange” event is triggered. By using the event, you can decide whether want to add or remove the object from the diagram. In the below code snippet, we can check the connector’s “sourceID” as node1  and “targetID” as node2. If the condition is satisfied, then set “cancel” arguments as true. So the newly added connector is removed from the diagram. Please refer to the code snippet in the below table. 
   
function collectionChange(args) {   
          if (args.state == 'Changing' && args.type == "Addition") {   
              var obj = args.element;   
              if (obj.sourceID == "node1" && obj.targetID == "node2") {   
                  args.cancel = true;   
              }   
            }   
      }   
 
   
If we misunderstood your requirement, then please share more details about your requirement like in which scenario you want to remove the connector or any pictorial representation of your requirement. This will be helpful for us to serve you better.
  
 

Regards  
Suganthi K.
  


Loader.
Up arrow icon