Reputation: 3940
I have a simple Yes No switch that is not displaying. It is showing as a checkbox.
<%= f.label :correct, "Correct Answer?" %><br>
<%= f.check_box :correct %>
<script>
$(document).ready(function(){
$("#answer_correct").bootstrapSwitch('onText', 'Yes');
$("#answer_correct").bootstrapSwitch('offText', 'No');
$("#answer_correct").bootstrapSwitch('size', 'large');
});
</script>
This is the console information:
<input id="question_answers_attributes_0_correct" name="question[answers_attributes][0][correct]" type="checkbox" value="1">
Am I missing something? Thank you
Upvotes: 0
Views: 149
Reputation: 2775
The JQuery ID selector isn't referencing that of the input element on the page.
Change $("#answer_correct")
to:
$("#question_answers_attributes_0_correct")
to select by the correct ID
or
$("[name='question[answers_attributes][0][correct]']")
to select the element by its name.
Upvotes: 1