Skip to content

Instantly share code, notes, and snippets.

@iWader

iWader/Markup.html

Last active Aug 29, 2015
Embed
What would you like to do?
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