Cabbage soup
Cabbage soup

Reputation: 1394

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

Upvotes: 8

Views: 8805

Answers (2)

James Lieu
James Lieu

Reputation: 196

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

Upvotes: 0

bunty
bunty

Reputation: 1098

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.

Upvotes: 7

Related Questions