Changing Bootstrap modal options on opening

I am trying to change the background setting of my modal to “static” as a response to an event so that it becomes unacceptable. I tried this by setting $('#myModal').modal({ backdrop: 'static',keyboard:false }) after clicking on the button inside the modal code, with no luck.

The effect I want is similar to the effect of nakupanda bootstrap-dialog (see the “Manipulating Buttons” section when dialog.setClosable(true); triggered by clicking the “Click to Disconnect and Unscrew” buttons, the modality no longer closes)

See jsfiddle .

I know this question has already been asked here , but it does not have the correct answer. I know this is possible somehow, but I cannot parse the nakupanda code.

+7
source share
5 answers

Try changing the modal parameter as shown below:

 $('#myModal').data('bs.modal').options.backdrop = 'static'; 

Here is a working example

+7
source

For those trying to do this on v4, you need to change:

 $("#myModal").data('bs.modal').options.backdrop = 'static'; 

to

 $("#myModal").data('bs.modal')._config.backdrop = 'static'; 
+1
source

You can try something like this: http://codepen.io/bwobst/pen/GrKBKy?editors=1010

 $('#open-modal').click(function(evt) { $('#myModal').modal({backdrop: 'static'}); $('.modal button').prop('disabled', true); }); 

When you press the "open modal" button, it sets the focus to static and disables the buttons in modal mode.

0
source

I came up with a solution. The problem is that even if you set the wallpaper to static, there is still a click listener.

My solution is here. https://jsfiddle.net/25zbf094/2/

Javascript

 $('#makeIndismissable').click(function(){ $('#myModal').prop('onclick',null).off('click'); }); $('#close').click(function(){ $('#myModal').modal("hide") }) 

I saved the HTML basically unchanged, but added the close identifier to the close button. And, as you can see above, you can still close the modality by clicking the X in the upper right corner.

0
source

Why don't you just initialize the modal option with the parameters when loading the page, and not by pressing a button?

just define the document ready by fn and paste the code below into it.

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

All Articles