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?
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});