jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.65k stars 722 forks source link

unable remove connection based on a condition. #680

Closed Ashvi213 closed 1 year ago

Ashvi213 commented 1 year ago

Hi,

I have 4 nodes in drawflow namely this.nodes = [ { name: 'node1' }, { name: 'node2' }, { name: 'node3' }, ]; i am creating connection like this this.editor.on('connectionCreated', (connection: any)

my connection object is { "output_id": "1", "input_id": "2", "output_class": "output_1", "input_class": "input_1" }

My scenarios:

  1. need to allow connection from node1 to node2 only
  2. If I tried to connect to node3 i need to remove that connection

so for removing connection

const sourceNode = this.editor.drawflow.drawflow[this.editor.module].data[sourceNodeId].data.name; const targetNode = this.editor.drawflow.drawflow[this.editor.module].data[targetNodeId].data.name; if (sourceNode === 'node1') { if (['node2'].includes(targetNode)) { console.log('Allow connection'); } else { const outputNode = this.editor.getNodeFromId(connection.output_id); const inputNode = this.editor.getNodeFromId(connection.input_id); this.editor.removeSingleConnection(outputNode, inputNode,connection.output_class, connection.input_class);
} }

but connection is not getting removed showing error.

thanks in advance

jerosoler commented 1 year ago

View:

Ashvi213 commented 1 year ago

Thank u