FileManager: Delete file with webix.confirm()

edited August 2019 in Technical questions

I want to add a warning before the user deletes a folder, because it will then delete everything inside of the folder.

This doesn't work:

       webix.confirm({
                  title: "Alert",
                  text: "Are you sure you want to this folder? \n \n This will delete everything inside this folder.",
                  type:"confirm-error"
                }).then(function(result){
                  model.remove({target: id}, (d)=>{
                    console.log(id);
                    webix.$$("ss_files").remove(id);
                    webix.$$("ss_files").deleteFile(id);
                  });
                })

It triggers onBeforeDelete so then this fires again, but removing the deleted file from the datastore with webix.$$("ss_files").remove(id) doesn't work, so it just goes in a loop.

Any ideas on how to solve this?

here is a snippet - https://snippet.webix.com/0bcu44j1

Comments

  • edited August 2019

    Hey @twigz, you should use file manager specific events and methods to avoid this issue.

    Firstly, instead of the onBeforeDelete use a onBeforeDeleteFile. The difference here is that this event only gets triggered via user action, so that means that the file/folder remove via API won't trigger a loop with this event.

    Secondly, to trigger the correct file deletion and its handling via inner file manager event you should use a deleteFile method insted of remove.

    The end result looks something like this: https://snippet.webix.com/hc3upw25.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!