Bootstrap: Opening a modal from another modal and modal-open

Created on 1 Sep 2016  路  8Comments  路  Source: twbs/bootstrap

When you open a modal from a link in another modal, it close the first modal to switch to the new one, but the body lose his "modal-open" class in the process.

js

Most helpful comment

Anyone looking to solve this, it's stupidly easy. Not sure why they're not implementing something similar to this. I think I'll submit a pull request for this if I can.

//Watch for closing modals
$('.modal').on('hidden.bs.modal', function () {
    //If there are any visible
    if($(".modal:visible").length > 0) {
        //Slap the class on it (wait a moment for things to settle)
        setTimeout(function() {
            $('body').addClass('modal-open');
        },200)
    }
});

All 8 comments

Multiple modals are currently not supported.

Yes I know, it's not the point. The issue is about the body class modal-open.

Duplicate of #17956.

Anyone looking to solve this, it's stupidly easy. Not sure why they're not implementing something similar to this. I think I'll submit a pull request for this if I can.

//Watch for closing modals
$('.modal').on('hidden.bs.modal', function () {
    //If there are any visible
    if($(".modal:visible").length > 0) {
        //Slap the class on it (wait a moment for things to settle)
        setTimeout(function() {
            $('body').addClass('modal-open');
        },200)
    }
});

@Fusty it's no a coplete solution. In my web app i keep permanently a padding on right of body after close the second modal.

Try putting the second modal outside the first modal.

@Fusty Thankyou very much!!

A detailed blog with an example: http://wp.me/p3Osmq-uf

Was this page helpful?
0 / 5 - 0 ratings