On making a component with local "f" form variable #810
Replies: 2 comments 4 replies
-
Where is the |
Beta Was this translation helpful? Give feedback.
3 replies
-
I did something similar for my project, but I'm rendering from a Phlex object, not from ERB, my code: class RadioCardComponent < Phlex::HTML
def inititalize(form:, attribute:, value:)
@form = form
@attribute = attribute
@value = value
end
private
attr_reader :form, :attribute, :value
def view_template
...
form.radio_button attribute, value
...
end
end
# Usage:
def view_template
form_with(...) do |form|
render RadioCardComponent.new(form:, attribute: :state, value: :draft)
render RadioCardComponent.new(form:, attribute: :state, value: :online)
end
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to gradually move from ERB to Phlex (2.0), and I have trouble factorizing this code into a Phlex Component:
Where
f
comes from a calling ERB view like<%= form.fields_for :rules do |rule_form| %>
I tried https://phlexing.fun 's suggestion but it did not work (the HTML generated is different from ERB).
I read through https://beta.phlex.fun/reference/rails/helpers.html but that did not help me with forms.
I tried finding example usage of common phlex rails helpers on github but found nothing on that subject.
Lastly, I tried playing with including these:
But still no luck, in fact the input does not even show up on the HTML.
My latest try:
When I only had the button, it worked fine, and my setup for Phlex otherwise seems correct, it is not my first component.
What am I missing?
--
EDIT:
To be clear, this is what I have right now:
In ERB:
Phlex component:
Beta Was this translation helpful? Give feedback.
All reactions