Open
Description
Hi, I have a use case in there I need to make some options of a check_boxes collection visible or hidden. If I could set a class on each item's wrapper depending on its attributes would be great because I can get some rendering like:
<div class="form-check custom-class">
<input class="form-check-input check_boxes optional" type="checkbox" value="1" name="xx">
<label class="collection_check_boxes" for="xx">Option 1</label>
</div>
<div class="form-check custom-class-2">
<input class="form-check-input check_boxes optional" type="checkbox" value="1" name="yy">
<label class="collection_check_boxes" for="yy">Option 2</label>
</div>
I think it could be done allowing a lambda on item_wrapper_class
option, passing to lambda function the current item
on rendering iteration, for example:
f.association :my_assoc,
item_wrapper_class: lambda { |item| item.active? 'custom-class-1' : 'custom-class-2' }
I tried with collection
making options as an array like [[label, id, { class: 'custom-class' }], [...], ...]
and it works but not as desired because it puts the class of course on the input element, but I need it on the item's wrapper.
Or actually is there another way to get it work as I need? I have not found any other solution.
Metadata
Assignees
Labels
No labels
Activity