Bootstrap Modal Backdrop = 'static' Not Working


Answer :

I found a workaround for this issue.

Once the modal has been hidden bootstrap data still remains on it. To prevent that I had the following:

$('#myModal').modal('show'); //display something //...  // if you don't want to lose the reference to previous backdrop $('#myModal').modal('hide');  $('#myModal').data('bs.modal',null); // this clears the BS modal data //...  // now works as you would expect $('#myModal').modal({backdrop:'static', keyboard:false}); 

I had the same problem with Bootstrap 4.1.1 and it only worked when I added the data attributes to the html

<div class="modal fade show" id="myModal" tabindex="-1" role="dialog"   style="display: block;" data-keyboard="false" data-backdrop="static"> ... 

Similar to Daniele Piccioni but a bit more concise:

$('#myModal').modal({backdrop: true, keyboard: false, show: true}); $('#myModal').data('bs.modal').options.backdrop = 'static'; 

This is for Bootstrap 3.+

See also: Change Bootstrap modal option once it already exists


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable