I want to show a twitter bootstrap modal as a response to a JS request. My show.js.erb function looks something like this:
$(document).ready(function() {
$('#dialog').modal('show')
});
Here "dialog" is the modal's id. The modal code itself looks something like this:
<div id="dialog" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close">×</a>
<h3> Showing Modal </h3>
</div>
<div class="modal-body">
I need to show up!
</div>
<div class="modal-footer">
<a href="#" class="btn primary">Done</a>
</div>
</div>
One thing I am sure of is that the javascript is being called. I can have it alter items on the page. Another thing is that modal is working fine. It shows up just fine when I use an HTML button to trigger the request like this:
<button data-controls-modal="dialog" data-backdrop="true" data-keyboard="true" class="btn danger"> Show </button>
Any idea why the modal doesn't show up on JS request?
Thank You!
This example works very well.
Best regards.
I have face the same problem and it has been solved as
try with this sequence.. Hope it works.
I had this problem and i fixed it by changing the javascript rendering to:
You can check more detailed explanation here https://kolosek.com/rails-creating-modals
That code looks like it should work (I'm doing something similar where I show the modal on document ready).
Check that you're loading the bootstrap-modal.js and make sure it's loading before your custom JS loads. If your custom JS is loading first, you'll see this behavior.
I had a similar problem, which I solved with a slight twist
My modal div is rendered on the calling page (from a partial) and not by the response of the JS request:
I use this link to rely on rails and Twitter unobtrusive JS:
and my show.js.erb looks like this (shortened)
This works fine and has the benefit of showing a "loading" animation to the user while the modal is being populated.
I had this problem,
the cause for me was setting the modal wholly in partial file and put the trigger (button / link) calling the modal from other view file.
So let say that the trigger button is in my index view page and I construct the modal in _form.html.erb file; And I want to create a new record from index page using that modal.
Solution:
index.html.erb - trigger button
index.html.erb - outermost of the modal
new.js.erb
P.S: pardon the new.js.erb I have no absolute reason enclosing the code untill the page is ready. I guess it will work even without the ready function; if you know is it necessary or not please do tell me.