首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用甜蜜警报来确认删除dropify.js的图像?

如何使用甜蜜警报来确认删除dropify.js的图像?
EN

Stack Overflow用户
提问于 2018-06-08 01:55:00
回答 2查看 2.2K关注 0票数 0

我想在删除图像之前使用甜蜜警报确认。但是,它不起作用。如果我使用javascript default confirm,它可以工作。我试着使用async和await,但是没有用。我如何修复/调试这个问题?

var pathURL = "file_path/";
var dropifyElements = {};
$('.dropify').each(function() {
    dropifyElements[this.id] = true;
});
var drEvent = $('.dropify').dropify();

drEvent.on('dropify.beforeClear', function(event, element) {
    id = event.target.id;
    if(dropifyElements[id]) {
        var x = false;
        return swal({   
            title: "Are you sure?",   
            text: "You will not be able undo this operation!",   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonColor: "#DD6B55",   
            confirmButtonText: "Yes, delete it!",   
            cancelButtonText: "No, cancel please!",   
            closeOnConfirm: false,   
            closeOnCancel: false 
        }, function(isConfirm){   
            if (isConfirm) {
                x = true;
            } else {     
                swal({
                    title:"Cancelled",
                    text:"Delete Cancelled :)",
                    type:"error",
                    timer: 2000,
                });
                x = true;
            } 
        });
        return x;
        //return confirm("Do you really want to delete this image?");
        // return confirm("Do you really want to delete \"" + element.file.name + "\" ?");
    }
});
EN

回答 2

Stack Overflow用户

发布于 2018-10-22 01:48:46

我读了答案,但我写了一个不同的想法。

var dropifyElements = {};
$('.dropify').each(function () {
    dropifyElements[this.id] = false;
});

dropElements.on('dropify.beforeClear', function (event, element) {
    id = event.target.id;
    if (!dropifyElements[id]) {
        swal({
            title: "¿Estás seguro?",
            text: "¿Realmente deseas eliminar el archivo \"" + element.file.name + "\" ?",
            icon: "warning",
            buttons: {
                cancel: "Cancelar",
                acept: "Aceptar"
            },
            dangerMode: true
        }).then((action) => {
            if (action == "acept") {
                dropifyElements[id] = true;
                element.clearElement();
            }
        });
        return false;
    }
    else
    {
        dropifyElements[id] = false;
        return true;
    }
});
票数 0
EN

Stack Overflow用户

发布于 2020-02-26 14:43:37

此代码还将解决甜蜜警报弹出窗口中单击取消按钮的问题

var drEvent = $('.dropify').dropify();

var hideConfirmBox = false;

drEvent.on('dropify.beforeClear', function(event, element){

    if (hideConfirmBox == false) {
        swal({
            title: 'Do you want to remove?',
            text: 'This will remove the selected image.',
            buttons: {
              cancel: true,
              confirm: {
                text: 'Yes, remove it!',
                value: 'proceed'
              }
            },
            dangerMode: true
        }).then((value) => {
            if (value == 'proceed') {
                $("body").trigger("click")
                hideConfirmBox = true;
                $(this).next('button.dropify-clear').trigger('click');
            }
        });
    }


    return hideConfirmBox;
});

drEvent.on('dropify.afterClear', function(event, element){
    hideConfirmBox = false;

    // call ur ajax here for deleting on clicking yes in sweet alert pop-up

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50747418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档