i trying use bootstrap buttons(http://getbootstrap.com/javascript/#buttons) checkboxes users has select 1 or many of options. each check box boolean column. code, when click on buttons, check boxes doesn't selected, neither state change.
<div class="btn-group btn-group-justified" data-toggle="buttons"> <%= f.label :tdm, class: "btn btn-primary" %> <%= f.check_box :tdm%> beginner <% end %> <%= f.label :domination, class: "btn btn-primary" %> <%= f.check_box :casual%> casual <% end %> <%= f.label :ctf, class: "btn btn-primary" %> <%= f.check_box :ctf%> competitive <% end %> <%= f.label :demolition, class: "btn btn-primary" %> <%= f.check_box :demolition%> competitive <% end %> </div>
what i'm trying accomplish https://jsfiddle.net/dtchh/12565/
the first thing need download bootstrap.min.js
here , put in vendor/assets/javascripts
folder. enable adding line:
//= require bootstrap.min
to app/assets/javascripts/application.js
file. can demonstrate part of problem going jsfiddle , disabling bootstrap.min.js
under "external resources".
however, buttons still not work because rails automatically generates hidden input
when use check_box
function , breaks bootstrap button. can stop creating hidden input
include_hidden: false
argument @ end of each of check_box
calls.
now, because of this post, think it's idea put hidden input
in form each of ones disabled. can put them somewhere won't break bootstrap buttons , overridden user input. anywhere in form before first check_box
label
should fine. should this:
<%= hidden_field(:your_model_name, :tdm, value: "0") %>
that should it.
*edited include replacing hidden inputs
Comments
Post a Comment