Using bootstrap with radio_buttons in rails
Asked Answered
F

2

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

Flashbulb answered 18/6, 2013 at 11:14 Comment(0)
Z
7

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.

Zaidazailer answered 18/6, 2013 at 12:34 Comment(1)
Need to include NAME to properly associate radio buttons, unless I am missing something w3schools.com/html/tryit.asp?filename=tryhtml_radioJudaic
H
0

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" %>
Hokanson answered 9/5, 2014 at 16:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.