Skip to content

Instantly share code, notes, and snippets.

@iWader
Last active August 29, 2015 14:06
Show Gist options
  • Save iWader/b3c5c7caac8316ad799d to your computer and use it in GitHub Desktop.
Save iWader/b3c5c7caac8316ad799d to your computer and use it in GitHub Desktop.
Bootstrap Radio Button Replacement
$('.form-replacement').each(function() {
var group = $(this);
var name = group.attr('data-toggle-name');
var hidden = $('input[name="' + name + '"]');
$('button', group).each(function() {
var button = $(this);
button.on('click', function() {
hidden.val($(this).val()).trigger('change');
if (hidden.val() == $(this).val())
{
$('button', group).removeClass('active');
$(this).addClass('active');
}
});
if (hidden.val() == button.val())
{
$('button', group).removeClass('active');
$(this).addClass('active');
}
});
});
<div class="btn-toolbar form-replacement" data-toggle-name="field_name">
<button type="button" value="true" class="btn btn-default">Yes</button>
<button type="button" value="false" class="btn btn-default">No</button>
</div>
<input name="field_name" type="hidden">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment