Use with the Bootstrap Button component.
<!-- Override the feedback icons position -->
<style type="text/css">
#buttonGroupForm .btn-group .form-control-feedback {
top: 0;
right: -30px;
}
</style>
<form id="buttonGroupForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label">Gender</label>
<div class="col-lg-9">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="gender" value="male" /> Male
</label>
<label class="btn btn-default">
<input type="radio" name="gender" value="female" /> Female
</label>
<label class="btn btn-default">
<input type="radio" name="gender" value="other" /> Other
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Languages</label>
<div class="col-lg-9">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="checkbox" name="languages[]" value="english" /> English
</label>
<label class="btn btn-default">
<input type="checkbox" name="languages[]" value="german" /> German
</label>
<label class="btn btn-default">
<input type="checkbox" name="languages[]" value="french" /> French
</label>
<label class="btn btn-default">
<input type="checkbox" name="languages[]" value="russian" /> Russian
</label>
<label class="btn btn-default">
<input type="checkbox" name="languages[]" value="italian"> Italian
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-9 col-lg-offset-3">
<button type="submit" class="btn btn-default">Validate</button>
</div>
</div>
</form>
$(document).ready(function() {
$('#buttonGroupForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
// Since the Bootstrap Button hides the radio and checkbox
// We exclude the disabled elements only
excluded: ':disabled',
fields: {
gender: {
validators: {
notEmpty: {
message: 'The gender is required'
}
}
},
'languages[]': {
validators: {
choice: {
min: 1,
max: 2,
message: 'Please choose 1 - 2 languages you can speak'
}
}
}
}
});
});