Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap (radio) button group in multiple lines

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?

like image 990
Mariano Avatar asked Sep 03 '15 21:09

Mariano


People also ask

How do you add radio buttons to groups?

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.

What is BTN-group?

“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 I make two buttons in one line in Bootstrap?

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.

What is button group in radio button?

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.


1 Answers

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>
like image 138
Ilya Kozhevnikov Avatar answered Oct 05 '22 16:10

Ilya Kozhevnikov