Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3, data-show not working

I'm using the modal-plugin supported by Bootstrap 3 (http://getbootstrap.com/javascript/#modals) with the following mark-up:

<div class=​"modal fade" id=​"login_modal" tabindex=​"-1" role=​"dialog" aria-labelledby=​"myModalLabel" aria-hidden=​"true" data-show=​"true">​…​</div>​

According to the documentation this should work with the data-show attribute.. Unfortunately the modal won't show automatically when the page finished loading. I don't see anything wrong here so I hope one of you guys could spot the problem for me please.

P.S.: I also found an similar existent but already closed issue they had with modals which seem to have been rewritten in v3 so I don't think it's up-to-date (https://github.com/twbs/bootstrap/issues/5891).

EDIT What I forgot to mention is that I included bootstrap of course. With a button to open and close it, it works just fine. :) It's really just the data-show attribute not doing what it's supposed to

like image 401
David Philip Avatar asked Sep 17 '13 16:09

David Philip


People also ask

How do I show modal?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.

How do I stop bootstrap modal pop up?

Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.

Which event fires immediately when the show instance method is called?

Collapse Events target is the element with the class="collapse" attribute. This event fires immediately when the show instance method is called. This event can be default prevented.

Which is used to show and hide the content in js using Bootstrap?

The collapse JavaScript plugin is used to show and hide content.


2 Answers

It's actually not a bug because the documentation says:

Shows the modal when initialized.

Therefore you need to initialize your Modal "manually" by JS:

<script type="text/javascript">
    $( function(){
        $('#myModal').modal();
    } )
</script>
like image 96
Karl Adler Avatar answered Sep 21 '22 19:09

Karl Adler


If data-show="true", then when you call $('.modal').modal(), the modal shows up. But if data-show="false", $('.modal').modal() doesn't work, you need to call $('.modal').modal('show') instead.

like image 33
Trantor Liu Avatar answered Sep 20 '22 19:09

Trantor Liu