当前位置: 动力学知识库 > 问答 > 编程问答 >

Using bootstrap with radio_buttons in rails

问题描述:

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

网友答案:

you can use like this,

<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>

here you need to give id to radiobutton and can assign the label to it by using for attribute in label tag. So that it can indicate corresponding radio button.

网友答案:

Correct me if I'm wrong but if you set the value attribute of the label the same as the radio button params, it would work the same way as assigning an id for the corresponding radio button

<%= f.radio_button :brand, "MNO", :style=>"display:none;" %>
<%= f.label :brand, "Third", value => "MNO", class="btn btn-primary" %>
分享给朋友:
您可能感兴趣的文章:
随机阅读: