using hidden_field #502
-
How do I provide for the adapter sufficiently?
renders:
whereas I'd like it to render:
(wrapping the form (in this case asset) nicely around the field attribute - as Rails does out-of-the-box so to speak) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I've solved this issue - not how I'd like it to work but ...
I don't get to enjoy the form_builder niceties but see the rendering I like
|
Beta Was this translation helpful? Give feedback.
-
The You should never need to use that adapter because it's better to work with the yielded form builder from the The That means you can call methods on the yielded form builder like this: class Foo < Phlex::HTML
include Phlex::Rails::Hepers::FormWith
def template
form_with(model: Post.new) do |f|
f.hidden_field :bar
end
end
end This is the equivalent of this in ERB and produces the same output. <%= form_with(model: Post.new) do |f| %>
<%= f.hidden_field :bar %>
<% end %> |
Beta Was this translation helpful? Give feedback.
The
HiddenField
adapter corresponds to this view helper https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-hidden_field_tagYou should never need to use that adapter because it's better to work with the yielded form builder from the
form_with
orform_for
adapters.The
FormWith
adapter yields an adapted Rails FormBuilder that corresponds to this https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.htmlThat means you can call methods on the yielded form builder like this:
This is the …