Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 422
Cabbage soup Avatar asked Jun 18 '13 11:06

Cabbage soup


1 Answers

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.

like image 198
bunty Avatar answered Nov 05 '22 03:11

bunty