I have a button group of several items that have to behave as radio buttons. I also need them broken into several rows and spanning the entire width of the container.
To this end I used bootstrap's class btn-group-justified
, and I split the <input type="radio">
elements into several button groups, while keeping the same name.
This looks ok, but has the side effect of buttons not toggling checked elements in other groups, even though they have the same name
. That is, they stop behaving as radio buttons in the same group.
Jsfiddle here. As you can see, if you select a button on the first row and then click one on the second, the first element isn't toggled off.
Is there a way to get a multiple-line button group without hacking the radio behavior together with javascript?
You group radio buttons by drawing them inside a container such as a Panel control, a GroupBox control, or a form. All radio buttons that are added directly to a form become one group. To add separate groups, you must place them inside panels or group boxes.
“Button Groups” in Bootstrap is a class of name “btn-group” which is used to create series of buttons in groups (without spaces) vertically or horizontally. This is the basic syntax of the button group class where each button has its own class of “btn”.
How do you put two buttons on the same line? If you have multiple buttons that should sit side-by-side on the same line, add the data-inline="true" attribute to each button. This will style the buttons to be the width of their content and float the buttons so they sit on the same line.
Defines a set of radio buttons, where only one button can be selected at a time. Each radio button group control has a property attribute that associates the group with a particular property. This property is defined elsewhere in the file and specifies the buttons that make up the group.
This did the trick.
http://www.bootply.com/k067OmtNXt
<div data-toggle="buttons">
<div class="btn-group btn-group-justified">
<label class="btn btn-default">
<input type="radio"> Lorem
</label>
</div>
<div class="btn-group btn-group-justified">
<label class="btn btn-default">
<input type="radio"> ipsum
</label>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With