Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap-modal doesn't show the dialog

I'm using bootstrap in rails application. I tried to show dialog box using bootstrap-modal, but the dialog box doesn't come for me. Here is my view code.

<div id="creative_attachment_popup" class="modal hide fade" role="dialog">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body">
    <p>Do you eant to continue../p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn">Close</a>
    <a href="#" class="btn btn-primary">Save changes</a>
  </div>
</div>

And simply, I call the js file as

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

the above code shows only a fade page and dosn't contain any dialog. When I type the above js line in my console it shows the following:

<div id=​"creative_attachment_popup" class=​"modal hide fade in ui-dialog-content ui-widget-content" role=​"dialog"> <h1 style=​"display:​ block;​" aria-hidden=​"false">​…​</div>​

Refer the above code with my html. Why am I getting this?

like image 665
Pez Avatar asked May 24 '13 07:05

Pez


People also ask

How do you show modal dialog?

The Window. showModalDialog() created and displayed a modal dialog box containing a specified HTML document.

How do I turn off modal dialog?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.


1 Answers

You have to include jQuery.js before, then bootstrap.js!!

And do not use simplified form of html for script. (like <script src=""/> ) you have to close it like <script src=""></script> )

<!-- JQuery -->
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js'></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

<!-- BootStrap Link -->
<link rel="stylesheet" type="text/css" href="/linker/styles/vendor/bootstrap.css">
<script type="text/javascript" src="/linker/js/vendor/bootstrap.js"></script>

Have you called $('#creative_attachment_popup').modal('show'); after the document is ready?

$(function() {
    $('#creative_attachment_popup').modal('show');
});
like image 51
The Finest Artist Avatar answered Sep 22 '22 01:09

The Finest Artist