Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bootbox closing when using custom dialog

Tags:

I'm using bootbox to show dialog.

If I use bootbox.confirm, bootbox.alert or bootbox.prompt, when pressing escape key or clicking outside the dialog, the dialog closed as expected

but when using bootbox.dialog, when I click outside the dialog or pressing escape key, the dialog doesn't close, how to make it behave as other dialog do?

var box = bootbox.dialog({     show: false,     backdrop: true,     animate: false,     title: 'Bla',     message: 'bla bla bla',     buttons: {         cancel: {             label: 'Cancel',             className: 'btn-warning'         },         save: {             label: 'Parse',             className: 'btn-success',             callback: function () {                 // handling with ajax                 return false;             }         }     } }); box.modal('show'); 
like image 587
Kokizzu Avatar asked Nov 05 '14 11:11

Kokizzu


People also ask

How do I close Bootbox dialog?

Pressing the ESC key or clicking close () dismisses the dialog and invokes the callback as if the user had clicked the Cancel button. Prompt dialogs require a callback function.


2 Answers

This should do it. Please note this has only been tested on v3. using bootstrap 2.3.2

$(document).on('click', '.modal-backdrop', function (event) {     bootbox.hideAll() }); 
like image 190
tibc-dev Avatar answered Sep 21 '22 20:09

tibc-dev


Add an onEscape callback function, which may have an empty body.

See docs and example.

Basic code:

bootbox.dialog({    onEscape: function() {},    // ... }); 
like image 32
bart Avatar answered Sep 21 '22 20:09

bart