-
Notifications
You must be signed in to change notification settings - Fork 17
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
Collection field components with block support #124
Comments
We did something similar for For
view_component-form/spec/view_component/form/label_component_spec.rb Lines 45 to 72 in d38c459
|
We've just come up against this today and it would be super useful to have. I started poking around to see if I could thread things through, but I can't quite wrap my head around it as in the collection checkbox case there's a new builder instantiated for each item in the collection here: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/actionview/lib/action_view/helpers/tags/collection_helpers.rb#L89 which I'm guessing would need to be yielded somehow. Will try to workaround it for now. |
@wooly I don't know if you're aware of the new compatibility module available in ViewComponent, to fix problems with blocks that we had in the past: ViewComponent/view_component#1650 Let us know if you figure out a workaround, it will be useful to fix this issue. And feel free to open a PR if you have time! |
I managed to get it working, but not in a super-idiomatic way. I've pushed up an example PR here: #142 The idea is to pass an additional proc option to use as the block for the render call, then strip that out of the options prior to render so the component can be initialized with the options-less-proc hash, then pass the proc as the block to render. |
@nicolas-brousse any feedback on that PR to validate that it's the right approach? |
Hi @wooly, Thank you for your interest in this. |
Thanks! I’m happy to knock it into shape with any feedback and flesh out some specs too. |
@wooly 👋 we reviewed your PR. We spent some time trying to find a way closer to Rails' syntax, but it seems to be quite a difficult task. For now, let's go with your suggestion! |
I found a need for this solution in my application and I used code similar to #148 for my radio buttons. I was wrong. The code I was using was essentially the default collection with no block rendering. I think the issue is calling the components in the block properly because I get parameter errors. |
I saw this comment in a past PR: #29 (comment) about adding collections without the block support first. I read through a number of issues in https://github.com/github/view_component related to form fields and it seems like it's not a simple problem to solve.
I'm curious whether there is a plan to support these fields when used with a block like so:
Right now the issue is that
b
is the component object rather than a builder object. I'm not sure what the right approach would be in a view component form builder.The text was updated successfully, but these errors were encountered: