Bootstrap: Fix reopening modal when modal already active

Created on 12 Jan 2017  路  6Comments  路  Source: twbs/bootstrap

I need open new modal from current modal by click button inside current modal.

Now i can do this only with crutch:

/* onening new modal when modal already active */
setTimeout(function() {
    $('#modal').modal();
}, 1000);

Otherwise i have error Uncaught Error: Modal is transitioning

Example here https://jsfiddle.net/rorc/nke1dvpz/

js v4

Most helpful comment

Its good, but i need return previous content of modal 1 and probably in future i need to 3'th modal...
Ok dude, thanks for reply, lets forget this 馃槂
Sigh, but i would be happy if bootstrap will starts support multiple modals native like this http://jsfiddle.net/CxdUQ/
Just amazing 馃槃

All 6 comments

I think this is a duplicate of #21607 which has a fix coming.

Instead of setting a timeout you should listen for the event hidden.bs.modal on your first modal.
That would indicate the first modal is closed and then you can open the second one.

Something like that:

$('#firstModal').one('hidden.bs.modal', function () {
    $('#secondModal').modal('show');
});

@vanduynslagerp Yea, but in my case code will big and dirty:

let editSelection = function(e) {
    const open = function() {
        $modal.modal({
            keyboard: false,
            backdrop: 'static'
        });
    };

    $modal.one('hidden.bs.modal', open);

    swal('Attention!', 'Save before open new modal?', 'warning').then(() => {
        $.post('/save', function() {
            $modal.modal('hide');
        }).catch(function() {
            $modal.off('hidden.bs.modal', open);
        });
    }, () => $modal.modal('hide'));
}

It doesn't seem particularly big or ugly.
That's how asynchronous calls are handled. Here is an example in Bootstrap modal unit tests.

I'm not exactly sure what you are trying to achieve here, but I gather that it would be something like that:

  1. Open modal 1
  2. User action
  3. Server call
  4. Close Modal 1
  5. Display Modal 2

Maybe, after the post, instead of closing modal 1 and opening Modal2, you could stay in Modal 1 and change it's content ? Like that:

  1. Open modal 1
  2. User action
  3. Server call
  4. Refresh modal 1 content

Its good, but i need return previous content of modal 1 and probably in future i need to 3'th modal...
Ok dude, thanks for reply, lets forget this 馃槂
Sigh, but i would be happy if bootstrap will starts support multiple modals native like this http://jsfiddle.net/CxdUQ/
Just amazing 馃槃

Close due to the merge of #21743 , fix will be available at our next release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devfrey picture devfrey  路  3Comments

vinorodrigues picture vinorodrigues  路  3Comments

bellwood picture bellwood  路  3Comments

athimannil picture athimannil  路  3Comments

IamManchanda picture IamManchanda  路  3Comments