Currently
modal-open
is assigned to the body when the modal is opened. How do i change where the class is added to instead of the body.
Thanks for any help.
If you want to prevent boostrap modal from closing by those actions, you need to change the value of backdrop and keyboard configuration. The default value of backdrop and keyboard is set to true . You can change the configuration in HTML or Javascript directly.
Static backdrop When backdrop is set to static, the modal will not close when clicking outside it.
The Best Answer is reset is dom build-in funtion, you can also use $(this). find('form')[0]. reset(); And Bootstrap's modal class exposes a few events for hooking into modal functionality, detail at here.
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.
You have to change js that adds modal-open. It's a bit strange as behaviour, anyway you can do it softly or brutally.
Softly: intercept modal click for show and remove class to body adding to another element:
// Modal is first added to the body element and then removed and added to another element
$('#myModal').on('shown.bs.modal', function (e) {
$('body').removeClass('modal-open');
$('#myCustomElement').addClass('modal-open');
})
and then intercept also the close of the modal and add an execution of a second remove:
$('#myModal').on('hidden.bs.modal', function (e) {
$('#myCustomElement').removeClass('modal-open');
})
Brutally method, to avoid that modal-open it's unnecessary added to body element: go in TwitterBootstrap directory > js Open modal.js Search for modal-open , you will find (on version 3.2.0):
in
Modal.prototype.show
you'll find
this.$body.addClass('modal-open')
in Modal.prototype.hide
you'll find
this.$body.removeClass('modal-open')
you have to change the target of addClass
and removeClass
and replace those instructions, if you have a fixed element it's enough simple (Ex: $('#myFixedElement').addClass('modal-open')
, if it's a dynamic element it's complex and you'll have again to intercept Show function to add a global var
in js to let modal.js
know and read your target element. However you can also change the signature of those functions but i don't really suggest you to do that, basically you'll make your code too hard to maintain.
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