Last active
August 29, 2015 14:06
-
-
Save iWader/b3c5c7caac8316ad799d to your computer and use it in GitHub Desktop.
Bootstrap Radio Button Replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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'); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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