Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple button groups - selection issue

I have 2 DYNAMICALLY created bootstrap button groups. When I select a button it works. But, as soon as I select another button, in the OTHER group, it de-selects the original one. So basically I can only have ONE button selected, even though they are in different button groups. Any idea why? The button groups ids are unique.

<div class="container">
  <h2>Button Group</h2>
  <div class="btn-group" id="group1">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
  <div class="btn-group" id="group2">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
   </div>
</div>
like image 245
WebDevGuy2 Avatar asked Aug 25 '16 14:08

WebDevGuy2


People also ask

How multiple buttons can be created at once by Bootstrap?

Instead of applying button sizing classes to every button in a group, just add . btn-group-* to each . btn-group , including each one when nesting multiple groups.

How do I make my BTN-Group responsive?

Add the . flex-wrap class to your button group container. Show activity on this post. If, like me, you don't necessarily need the buttons to be in a group, you could also use the btn-toolbar class which defines flex-wrap: wrap by default.

Does button group allows multiple buttons to be stacked together on a single line?

Button groups allow multiple buttons to be stacked together on a single line. This is useful when you want to place items like alignment buttons together. You can add on optional JavaScript radio and checkbox style behavior with Bootstrap Button Plugin. This class is used for a basic button group.

What is a button group which control is generally used with a button group?

Answer: The ButtonGroup control manages the selected/unselected state for a set of buttons. For the group, the ButtonGroup instance guarantees that only one button can be selected at a time. Generally, we use Radio Button control with a button group.


1 Answers

This will solve your problem.

<div class="container">
  <h2>Button Group</h2>
  <div class="btn-group" data-toggle="buttons">
    <label for="" class="btn btn-primary">
        <input type="radio" >Apple
    </label>
    <label for="" class="btn btn-primary">
        <input type="radio" >Samsung
    </label>
    <label for="" class="btn btn-primary">
        <input type="radio">Sony
    </label>
  </div>

  <div class="btn-group" data-toggle="buttons">
     <label for="" class="btn btn-primary">
        <input type="radio" >Apple
     </label>
     <label for="" class="btn btn-primary">
        <input type="radio" >Samsung
     </label>
     <label for="" class="btn btn-primary">
        <input type="radio" >Sony
     </label>
   </div>
</div>
like image 127
Khurram Avatar answered Oct 06 '22 17:10

Khurram