Home:ALL Converter>Wait for Sweetalert2 async confirm before continuing filepredelete event in bootstrap-fileinput

Wait for Sweetalert2 async confirm before continuing filepredelete event in bootstrap-fileinput

Ask Time:2018-05-21T14:08:51         Author:Vince Parker

Json Formatter

Having some issues with the plugin Bootstrap File Input and SweetAlert2

This is for showing a dialog box to confirm if the user really wants to proceed with deleting the file.

I need to return a boolean for filepredelete event if I'm going to abort the deletion of the file. The function is synchronous but I'm using an asynchronous plugin SweetAlert2 with promises.

Here's my code:

$("#gallery-images").fileinput({
           ...

}).on("filepredelete", function(event, key, jqXHR, data) {

    swal({
        title: 'Are you sure you want to delete this image?',
        showCancelButton: true,
        confirmButtonText: 'Confirm',
        cancelButtonText: 'Cancel',
        type: 'warning',
    }).then((result) => {
        if(result.value){
            return false;
        }
        return true;
    });

});

I can't find a way to wait for the confirmation. I'm thinking of just always abort the deletion and just manually delete the file when the user confirmed. I need to refactor my code.

Author:Vince Parker,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50442929/wait-for-sweetalert2-async-confirm-before-continuing-filepredelete-event-in-boot
yy