Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape? [duplicate]

I'm using the Twitter Bootstrap modal as a wizard window, and would like to prevent the user from closing it when clicking outside of the modal or when pressing escape. Instead, I want it to be closed when the user presses the finish button. How could I achieve this scenario?

like image 894
Ehsan Zargar Ershadi Avatar asked Apr 22 '13 16:04

Ehsan Zargar Ershadi


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?

Another way to dismiss the modal when clicking outside involved taking advantage of the bubbling nature of the javascript events. clicking on . modal will cause the click event to propagate like this . modal -> #modal-root -> body while clicking outside the modal will only go through #modal-root -> body .

How do you prevent modal from closing when clicking outside Angularjs?

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.

What is backdrop static in modal?

The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not.


2 Answers

Works too, data-backdrop="static" to click out and data-keyboard="false" to Esc in your div modal:

<div id="idModal" class="modal hide" data-backdrop="static" data-keyboard="false"> 
like image 24
CesarMiguel Avatar answered Oct 13 '22 00:10

CesarMiguel


If using JavaScript then:

$('#myModal').modal({     backdrop: 'static',     keyboard: false }) 

or in HTML:

<a data-controls-modal="your_div_id" data-backdrop="static" data-keyboard="false" href="#"> 
like image 57
Ehsan Zargar Ershadi Avatar answered Oct 12 '22 22:10

Ehsan Zargar Ershadi