Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Show/collapse div with bootstrap 3

bootstrap3 jquery javascript

  • Please log in to reply
2 replies to this topic

#1 ugrum

ugrum

    Passenger

  • Members
  • 1 posts

Posted 11 November 2013 - 02:56 PM

Im trying to render a form when the user clicks a button, so far I got:

<%= link_to 'Answer this', '#', :class => "btn btn-default", "data-toggle" => "collapse","data-parent" => "#accordion", "data-target" => "#answer_form#{question.id}" %>
<%= render partial: 'answers/form', :locals => {:answer => question.answers.build} %>

And the partial:

 <div id="answer_form<%= answer.question.id%>" class="collapse">
         <%= form_for(answer) do |f| %>
         <% if answer.errors.any? %>
         <div id="error_explanation">
           <h2><%= pluralize(answer.errors.count, "error") %> prohibited this answer from being saved:</h2>
       
           <ul>
             <% answer.errors.full_messages.each do |msg| %>
             <li><%= msg %></li>
             <% end %>
           </ul>
         </div>
         <% end %>
       
         <div class="field">
           <%= f.label :content %><br>
           <%= f.text_area :content %>
         </div>
         <div>
           <%= f.label :question %>
           <%= f.collection_select(:question_id, @questions, :id, :title) %>
         </div>
         <div class="actions">
           <%= f.submit %>
         </div>
         <% end %>
 </div>

When I click the Answer button, the answer_form starts to appear but then I hides again.



#2 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 November 2013 - 04:11 PM

Perhaps because you are telling it to collapse?

"data-toggle" => "collapse"

Perhaps it would be simpler to use jQuery and unobtrusive javascript with the toggle?

 

It's an old cast but I think is still current http://railscasts.co...sive-javascript


Programming is just about problem solving!


#3 klyrish

klyrish

    Signalman

  • Members
  • 10 posts
  • LocationDenver, CO

Posted 20 November 2013 - 04:33 PM

I've been having issues with Bootstrap 3.0 and showing/hiding divs. The error is that they no longer show. The exact same jQuery works flawlessly with Bootstrap 2.0, but 3.0 has clearly changed something.

 

Sorry, I know this post isn't of any help, but I'm definitely curious to find out if you come up with a solution. I get no usable error from the Rails console or from the Chrome javascript console (nothing at all happens in there).







Also tagged with one or more of these keywords: bootstrap3, jquery, javascript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users