With Bootstrap 3.2, place the hidden input in the middle of the button group container. Instead of textual content, we take the value of the data field.
<div id="test" class="btn-group checkit" data-toggle="buttons-radio"> <button type="button" data-value="1" class="btn btn-default active">Yes</button> <input type='hidden' name="testfield" value='1'> <button type="button" data-value="0" class="btn btn-default ">No</button> </div>
Now insert a small javascript fragment into the download part of your template.
$('.checkit .btn').click(function() { $(this).parent().find('input').val($(this).data("value")); });
Therefore, you only need to add .checkit to the button group and insert a hidden input field.
With bootstrap 3.2 you can directly use button groups with radio or checkbox inputs
<div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="options" id="option1" value="1" /> Yes </label> <label class="btn btn-default"> <input type="radio" name="options" id="option2" value="0" /> No </label> <label class="btn btn-default"> <input type="radio" name="options" id="option3" value="42" /> Whatever </label> </div>
See here: http://jsfiddle.net/DHoeschen/gmxr45hh/1/
RubbelDeCatc Aug 25 '14 at 17:26 2014-08-25 17:26
source share