简体   繁体   中英

How can I make a Bootstrap 3 Collapse work with SimpleForm checkbox in Rails 4?

I am trying to use the Bootstrap Collapse to open a section only if the box here is checked. I am using SimpleForm and Bootstrap 3 . I can get the toggle to work fine in the page with a normal link, but I can't get SimpleForm to put the data-toggle bit in.

I need this in input:

 data-toggle="collapse"  href="#collapseOne"

<%= f.input :boolean_question, inline_label: 'Check if true'%>

在此处输入图片说明

Any ideas on how to make this happen? I have tried input_html: and wrapper_html:

UPDATE: for now this is my solution without simple_form:

<%= form_for(@model) do |f| %>

<%= f.check_box :boolean_question, data: {'toggle' =>  "collapse", 'target' =>  "#collapse_section"} %>

<div id="collapse_section" class="collapse">
  Data that was hidden
</div>

I got it working with this:

<%= f.input :boolean_question, label: false, inline_label: 'Check if Yes',
input_html: { data: {'toggle' =>  "collapse", 'target' =>  "#collapse_section"} } %>

Plus:

   <div id="collapse_section" class="collapse">
       <p>hidden stuff that will be revealed.</p>
   </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM