Callback Ignored on Confirm Modal
I am trying to modify a script that used traditional confirm modal. When I try to replace it with bootbox, the script does not wait for the callback function like it does for the traditional conform dialog. Any help would be appreciated.
$data.checkExists = function(file) { if ($.inArray('onCheck', settings.overrideEvents) < 0) { // This request needs to be synchronous $.ajaxSetup({ 'async' : false }); // Send the filename to the check script var checkData = $.extend(settings.formData, {filename: file.name}); $.post(settings.checkScript, checkData, function(fileExists) { file.exists = parseInt(fileExists); }); if (file.exists) {
if (!confirm('A file named ' + file.name + ' already exists in the upload folder.\nWould you like to replace it?')) {
// If not replacing the file, cancel the upload
methods.cancel.call($this, file);
return true;
}
}
}
// Trigger the check event
if (typeof settings.onCheck === 'function') {
settings.onCheck.call($this, file, file.exists);
}
return false;
}
I tried replacing the !(confirm......) { } statement with all available examples but the script just ignores it and continues. Any help would be appreciated.
bootbox.confirm(message, function(result) {
if (result) {
$.ajax({
...
})
.done(functioni(data) {
if (!data.success) {
$.bootbox.alert('Error');
return false;
}
// Do something
bootbox.hideAll();
});
return false; // Add this line, The model will not close.
}
});
Your problem lies in the fact that bootbox is asynchronous, whereas a low-level confirm will block until dismissed. You need to follow the callback style used in the examples and tutorials and you should be fine :).