我想在删除图像之前使用甜蜜警报确认。但是,它不起作用。如果我使用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 + "\" ?");
}
});
发布于 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;
}
});
发布于 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
});
https://stackoverflow.com/questions/50747418
复制相似问题