Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item_wrapper_class with lambda #1716

Open
camilova opened this issue Oct 20, 2020 · 0 comments
Open

item_wrapper_class with lambda #1716

camilova opened this issue Oct 20, 2020 · 0 comments

Comments

@camilova
Copy link

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.

@camilova camilova changed the title input_wrapper_class with lambda item_wrapper_class with lambda Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant