user1261774
user1261774

Reputation: 3695

upgrade to bootstrap 3 - jquery call to modal fails (but works in v2.3)

I have upgraded my test site from bootstrap version 2.3 to version 3.3.5.

When I replaced the bootstrap.min.js file from v2.3 to v3.3.5, one part of my jquery code does not get called with v3.3.5 of bootstrap.min.js, but is called in v2.3.

After a lot of time and effort, I have been able to pinpoint where the error occurs, but I am unable to understand why this error occurs with v3.3.5 (but does work with v2.3) and I am also unable to figure out how to fix this myself. My Jquery skills are not strong.

Here is the code that I have (I have put in alerts to help me identify what is not working and what is working):

....
$('#change_formatting_style_button').click(function() {
    alert('a');
    if (! $('#change_formatting_style_button').attr('disabled')) {
        alert('b');
        $('#preview_modal').modal();  // this line is not called in v3.3.5.
        alert('c');
    }
    alert('d');
    return false;
});
....

In version 2.3 of the bootstrap.min.js, the line $('#preview_modal').modal(); is called, but in version 3.3.5 it is not called. I am unsure why this fails in v3.3.5.

Below is the function that is not called:

$('#preview_modal').on('shown', function() {
    alert('0');
    $('#preview_contents').html($('#live_preview').html());
    alert('1');

});

I have searched SO and Google for assistance, but I am unable to shed any light on this.

I am hoping that someone can point out what I have done wrong and how I can fix this issue.

Upvotes: 0

Views: 377

Answers (1)

Charlie Harster
Charlie Harster

Reputation: 83

Your modal is initialized, but isn't shown yet. Try using:

 $('#preview_modal').modal('show');

Upvotes: 1

Related Questions