Reputation: 365
anybody know how to fix this. I have this code to show bootbox.confirm when deleting a file, but it's not working.
$('#fileupload').fileupload({
destroy: function (e, data) {
var that = $(this).data('fileupload');
if (bootbox.confirm("Delete this file(s) ?") == true ) {
if (data.url) {
$.ajax(data)
.success(function () {
$(this).fadeOut(function () {
$(this).remove();
});
});
} else {
data.context.fadeOut(function () {
$(this).remove();
});
}
}
}
});
Upvotes: 2
Views: 661
Reputation: 1283
You have to use callback in order to determine user response for confirm and prompt dialogs.
This is the signature for confirm: bootbox.confirm(message, callback)
.
Your code should be like this
$('#fileupload').fileupload({
destroy: function (e, data) {
var that = $(this).data('fileupload');
bootbox.confirm("Delete this file(s) ?", function(result) {
if(result == true){
if (data.url) {
$.ajax(data)
.success(function () {
$(this).fadeOut(function () {
$(this).remove();
});
});
} else {
data.context.fadeOut(function () {
$(this).remove();
});
}
}
});
}
});
Upvotes: 1
Reputation: 413702
The Bootbox methods don't work like the native methods:
bootbox.confirm("Delete this file(s) ?", function(answer) {
if (!answer) return; // User said "no"
if (data.url) {
$.ajax(data)
.success(function () {
$(this).fadeOut(function () {
$(this).remove();
});
});
} else {
data.context.fadeOut(function () {
$(this).remove();
});
}
}
Upvotes: 1