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/
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.
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 .
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 .
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') .
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' })
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With