bootstrap_form
bootstrap_form copied to clipboard
collection_check_boxes with custom: true doesn't allow select
trafficstars
the issue is present because the collection_check_boxes method doesn't generate id's for the input elements nor a for attribute for the label which breaks the check box.
My suggestion is as follows: if a custom id is not present generate an id as follows "#{input_name}_#{value}" to ensure it being unique
I looked into the source code and couldn't find the origin of the problem. if someone can guide me i'll be happy to submit a PR
after digging a little further i downloaded the source and added a test case for a collection with custom input and it indeed rendered correctly. i'm guessing i have a gem that is interfering with something
<%= bootstrap_form_with(model: project, local: true) do |form| %>
<%= form.collection_check_boxes(:service_ids, Service.active, :id, :name, label: "Services", custom: true) %>
<% end %>
output:
<input value="" multiple="multiple" type="hidden" name="project[service_ids][]">
<div class="form-group">
<label>Services</label>
<div class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="8" checked="checked"
name="project[service_ids][]">
<label class="custom-control-label">Branding</label>
</div>
<div class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="7"
name="project[service_ids][]">
<label class="custom-control-label">Marketing</label>
</div>
</div>