8

Is it possible to use the bootstrap radio buttons i.e:

    <div class="btn-group" data-toggle="buttons-radio">
    <button type="button" class="btn btn-primary">someValue</button>

with a form_for in rails? There is a radio_button method:

    <%= radio_button("object", "method", "someValue") %>

, but I wasn't able to style it. I didn't know if there is someway to merge the two to give the radio button the bootstrap appearance of the first snippet. Thanks, Sam

4

2 回答 2

7

你可以这样使用,

<div class="btn-group" data-toggle="buttons-radio">
  <%= f.radio_button :brand, "ABC", :id=>"first", :style=>"display:none;" %>
  <label for="first" class="btn btn-primary">First</label>

  <%= f.radio_button :brand, "PQR", :id=>"second", :style=>"display:none;" %>
  <label for="second" class="btn btn-primary">Second</label>

  <%= f.radio_button :brand, "MNO", :id=>"third", :style=>"display:none;" %>
  <label for="third" class="btn btn-primary">Third</label>
</div>

在这里,您需要为单选按钮提供 id,并可以通过在标签标签中使用for属性为其分配标签。以便它可以指示相应的单选按钮。

于 2013-06-18T12:34:45.887 回答
0

如果我错了,请纠正我,但如果您将标签的value属性设置为与单选按钮参数相同,则其工作方式与为相应单选按钮分配 id 相同

<%= f.radio_button :brand, "MNO", :style=>"display:none;" %>
<%= f.label :brand, "Third", value => "MNO", class="btn btn-primary" %>
于 2014-05-09T16:04:03.903 回答