I would like to use this from Bootstrap but with my Laravel Collective functions the option state button won't change to the correct state. So I want to change it myself with jQuery.
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Active
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option2" autocomplete="off"> Radio
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option3" autocomplete="off"> Radio
</label>
</div>
(original HTML from getbootstrap.com)
Which I re-wrote to:
<div id ="addproductsort" class="btn-group btn-group-toggle" data-toggle="buttons">
<label id="productsort" class="btn btn-secondary active">
{{Form::radio('options', 'one', false, ['name' => 'options', 'autocomplete' => 'off', 'class' => 'productsortoption'])}}
one
</label>
<label id="productsort" class="btn btn-secondary">
{{Form::radio('options', 'two', false, ['name' => 'options', 'id' => 'option2', 'autocomplete' => 'off', 'class' => 'productsortoption'])}}
two
</label>
<label id="productsort" class="btn btn-secondary">
{{Form::radio('options', 'three', false, ['name' => 'options', 'id' => 'option2', 'autocomplete' => 'off', 'class' => 'productsortoption'])}}
three
</label>
</div>
This is the script I got:
$('#productsort').each(function() {
$(this).on('click', function() {
if($(this).hasClass('active')) {
$(this).children().attr( "checked", "checked" );
};
});
});
When I click the first button one
, the state of the option child
does change, but when I click the second or the third button nothing happens.
What's wrong in here? Thanks in advance.