I have this function -
function startReview(response_message, prompt, model, reviewable_id, reviewable_type, user_id) {
bootbox.hideAll();
if (response_message && response_message.length > 0) {
response_message = response_message.replace(/\n/g, '<br/>');
var message = response_message
message += '...';
var dialog = bootbox.dialog({
message: message,
closeButton: false,
buttons: {
thumbs_up: {
label: '<i class="fa fa-thumbs-up"></i>',
className: 'btn-success',
callback: function () {
saveUserFeedback(true, prompt, response_message, model, reviewable_id, reviewable_type, user_id);
dialog.modal('hide');
return false;
}
},
thumbs_down: {
label: '<i class="fa fa-thumbs-down"></i>',
className: 'btn-danger',
callback: function () {
saveUserFeedback(false, prompt, response_message, model, reviewable_id, reviewable_type, user_id);
dialog.modal('hide');
return false;
}
},
},
});
$('.bootbox .btn-success, .bootbox .btn-danger').parent().css('text-align', 'center');
} else {
bootbox.alert("...");
}
}
The user gets a thumbs up and down buttons that has a callback by pressing one of them. I want the user to be unable to close the bootbox by 'esc' button. I tried these -
$(document).on('keydown.dismiss.bs.modal', function (e) {
debugger
if (e.which == 27) {
e.preventDefault();
}
});
tried to add this below the dialog declaration -
dialog.init(function () {
dialog.find('.modal-content').on('keydown.dismiss.bs.modal', function (e) {
if (e.which == 27) {
e.stopPropagation();
}
});
});
tried to add onEscape: null
none of them worked. if i add a debugger inside the if (e.which == 27) block, the debugger stops and when I allow the code to run it looks like it is preventing the bootbox from closing. Without debugging, it doesn't seem to work. When I run the code on the console, it prevents it from closing the window.
Any ideas why is this happening or what else can I check?