Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular js: Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?

Am using the angular bootstrap to present a modal. But my requirement is to prevent pop-up dismissal when clicking outside the modal, or when the escape key is pressed.

I followed the tutorial on the angular bootstrap site :http://angular-ui.github.io/bootstrap/

enter image description here

like image 949
Vinodh Avatar asked Jan 16 '14 08:01

Vinodh


People also ask

How do I keep my Bootstrap modal from closing when I click outside?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How do I hide the modal when I click outside?

modal -> #modal-root -> body while clicking outside the modal will only go through #modal-root -> body . Since we can stop the propagation of click events completely, and if that does not interfere with any other code, we only need to listen for click events in both .

How do I disable modal backdrop?

On Options chapter, in the page you linked, you can see the backdrop option. Passing this option with value 'static' will prevent closing the modal. As @PedroVagner pointed on comments, you also can pass {keyboard: false} to prevent closing the modal by pressing Esc .

How do I stop Bootstrap modal pop-up?

Answer: Use the modal('hide') Method You can simply use the modal('hide') method to hide or close the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('show') and modal('toggle') .


2 Answers

Use:

backdrop: 'static' 

backdrop - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), 'static' - backdrop is present but modal window is not closed when clicking outside of the modal window.

For example:

$modal.open({       templateUrl: 'myModalContent.html',       controller: ModalInstanceCtrl,       backdrop: 'static'     }) 
like image 97
CD.. Avatar answered Oct 04 '22 13:10

CD..


Add both backdrop: static and keyboard: false to your modal options. The first one disables the background click, the second one the escape key.

backdrop: 'static' - backdrop is present but modal window is not closed when clicking outside of the modal window.

keyboard - indicates whether the dialog should be closable by hitting the ESC key, defaults to true.

Example:

$modal.open({   templateUrl: 'template.html',   controller: TheController,   backdrop: 'static',   keyboard: false }) 

See the docs for more information.

like image 20
theDmi Avatar answered Oct 04 '22 15:10

theDmi