我在 Rails 4 中有一个表单,我想使用 Bootstrap 的单选按钮来设置二进制值,而不是使用复选框。
我使用Bootstrap 的示例作为参考。
我希望它看起来像这样:
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="options" id="option1"> True
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option2"> False
</label>
</div>
http://jsfiddle.net/52VtD/3456/
但这是我到目前为止所拥有的(使用 HAML):
.btn-group{"data-toggle" => "buttons"}
%label.btn.btn-default
= f.radio_button :single_use, true
True
%label.btn.btn-default
= f.radio_button :single_use, false
False
产生:
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<label class="radio" for="something_single_use_true">
<input id="something_single_use_true" name="something[single_use]" type="radio" value="true">
</label>
Single use
</label>
<label class="btn btn-default">
<label class="radio" for="something_single_use_false">
<input checked="checked" id="something_single_use_false" name="something[single_use]" type="radio" value="false">
</label>
Unlimited use
</label>
</div>
我也在使用rails-bootstrap-forms。
更新:在 Chrome 的 DevTools 中玩耍,如果我将样式添加display: none;
到线条中,我可以使按钮看起来像我想要的那样(无单选按钮)
<label class="radio" for="something_single_use_true">
...
<label class="radio" for="something_single_use_false">
但我不确定如何在 HAML 中执行此操作并在 Rails 中使用 Form Helper,因为我相信这些特定行是为我生成的。