Sharing object with child components #508
Unanswered
scottwater
asked this question in
Q&A
Replies: 1 comment
-
Hey! I think that by doing this, you're swimming against the current. Rails already does an amazing job at handling forms and its rendering. To use components in forms, approach it from the opposite perspective: how do you enhance form helpers to use your components underneath? The answer is Using form builders you can:
You can either override the default rails form builder: class FormBuilder < ActionView::Helpers::FormBuilder
def text_field(...)
# this will override rails' default text_field
end
end Or create your own and specify which controllers or forms should use it module YourApp # Or any name
class FormBuilder < ActionView::Helpers::FormBuilder
def chip_selector(args)
# this will add a new chip_selector helper for your forms
# e.g. f.chip_selector :tag_id (if you had a tag model for example)
YourChipSelectorComponent.new(...)
end
end
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to build a couple of components that will simply building repetitive forms.
I started with just the individual fields:
However, I found I still had a lot of boilerplate form set up (title, description, layers of divs, etc), so I was trying to wrap that up in a parent/container form:
I have something that looks like this:
I have hit a road block trying to figure out how to share the "form_with" from my parent component with the child components (or if that is even a good idea).
Any suggestions on how to move forward?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions