Commit 700e4662 by benjaoming

Fixing js bug in SelectWidgetBootstrap

parent 4162909f
...@@ -78,27 +78,26 @@ class SelectWidgetBootstrap(forms.Select): ...@@ -78,27 +78,26 @@ class SelectWidgetBootstrap(forms.Select):
js = (""" js = ("""
<script type="text/javascript"> <script type="text/javascript">
function setBtnGroupVal(elem) { function setBtnGroupVal(elem) {
selected_a = $(elem).parentsUntil('ul').find('a[selected]'); btngroup = $(elem).parents('.btn-group');
selected_a = btngroup.find('a[selected]');
if (selected_a.length > 0) { if (selected_a.length > 0) {
val = selected_a.attr('data-value'); val = selected_a.attr('data-value');
label = selected_a.html(); label = selected_a.html();
} else { } else {
$(elem).parentsUntil('ul').find('a').first().attr('selected', 'selected'); btngroup.find('a').first().attr('selected', 'selected');
setBtnGroupVal(elem); setBtnGroupVal(elem);
} }
alert(val); btngroup.find('input').val(val);
$(elem).val(val); btngroup.find('.btn-group-label').html(label);
$(elem).parents('.btn-group').find('.btn-group-label').html(label);
} }
$(document).ready(function() { $(document).ready(function() {
$('.btn-group-form input').each(function() { $('.btn-group-form input').each(function() {
setBtnGroupVal(this); setBtnGroupVal(this);
}); });
$('.btn-group-form li a').click(function() { $('.btn-group-form li a').click(function() {
$(this).parent().siblings().find('a').attr('selected', ''); $(this).parent().siblings().find('a').attr('selected', false);
$(this).attr('selected', 'selected'); $(this).attr('selected', true);
setBtnGroupVal($(this).parentsUntil('div').parent().find('input.btn-group-value').first()); setBtnGroupVal(this);
alert($(this).parentsUntil('div').parent().find('input.btn-group-value').first().val());
}); });
}) })
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment