jerosoler / Drawflow

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

How do I close/disable the remove node event using the delete button? #70

Closed bankkokbank closed 3 years ago

bankkokbank commented 3 years ago

i want to create confirmation popup before delete node (using delete button). Just in case I use the delete button and use the onkeydown event but the node delete event first and confirmation popup follows after.

MehbubRashid commented 3 years ago

@BankkokBank you can simply hide the default delete button and implement your own in node html...

jerosoler commented 3 years ago

Hello @BankkokBank

The option that comments @MehbubRashid is correct.

Another option is to overwrite the function:

editor.removeNodeId = function(id) {
      var r = confirm("Are you sure to delete?");
      if (r == true) {
        this.removeConnectionNodeId(id);
        var moduleName = this.getModuleFromNodeId(id.slice(5))
        if(this.module === moduleName) {
          document.getElementById(id).remove();
        }
        delete this.drawflow.drawflow[moduleName].data[id.slice(5)];
        this.dispatch('nodeRemoved', id.slice(5));
      }
    }
bankkokbank commented 3 years ago

Thank you for suggest, It work for me