Bootstrap nested button groups with radiobutton behavior

4.2k Views Asked by At

Using Twitter Bootstrap, I have a button group with several sets of buttons. Some of these buttons have dropdowns. I would like this button group to have radiobutton-style behavior, as per radio in bootstrap's JavaScript button section. Here's my JS Fiddle and corresponding code:

<div data-toggle="buttons" class="btn-group">
    <label class="btn btn-default active">
        <input type="radio" name="options">General</label>
    <div class="btn-group">
        <label data-toggle="dropdown" class="btn btn-default dropdown-toggle">
            <input type="radio" name="options">Users <span class="caret"></span>
        </label>
        <ul class="dropdown-menu">
            <li><a href="#">1</a>
            </li>
            <li><a href="#">2</a>
            </li>
        </ul>
    </div>
    <div class="btn-group">
        <label data-toggle="dropdown" class="btn btn-default dropdown-toggle">
            <input type="radio" name="options">Assignments <span class="caret"></span>
        </label>
        <ul class="dropdown-menu">
            <li><a href="#">1</a>
            </li>
            <li><a href="#">2</a>
            </li>
        </ul>
    </div>
    <div class="btn-group">
        <label data-toggle="dropdown" class="btn btn-default dropdown-toggle">
            <input type="radio" name="options">Other <span class="caret"></span>
        </label>
        <ul class="dropdown-menu">
            <li><a href="#">1</a>
            </li>
            <li><a href="#">2</a>
            </li>
        </ul>
    </div>
</div>

Does Bootstrap have this capability?

1

There are 1 best solutions below

1
On

Is this what you are looking for?

http://jsfiddle.net/6m5Bp/1/

I embedded the option buttons in a drop-down ul menu....

<div class="btn-group" data-toggle="buttons">
 <label class="btn btn-primary">
  <input type="radio" name="options" id="option1"> Option 1
 </label>
 <label class="btn btn-primary">
  <input type="radio" name="options" id="option2"> Option 2
 </label>
 <label class="btn btn-primary">
   <a data-toggle="dropdown" href="#" style="color:#fff;">More Options</a>
     <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
      <li><label class="btn btn-primary"><input type="radio" name="options" id="option4"> Option 4</label></li>
      <li><label class="btn btn-primary"><input type="radio" name="options" id="option5"> Option 5</label></li>
     </ul>
 </label>
</div>