Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal backdrop = 'static' not working

Tags:

First, I open my modal using this:

$('#myModal').modal('show');

Then, in another situation, I need that this same modal does not close when pressing ESC/clicking outside, so I use this:

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

But once I open my modal by the first method, the second one doesn't work. Any hints?

How can I force backdrop value switch to work?

like image 996
João Paulo Avatar asked Dec 23 '15 17:12

João Paulo


1 Answers

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});
like image 71
Daniele Piccioni Avatar answered Sep 19 '22 17:09

Daniele Piccioni