How do I access changeset data in my HTML, passed in via form: to_form(changeset)
, when not using a Phoenix input
component? Am I really supposed to do this:
<p><%= @form[:foo].value %></p>
Or am I missing something?
How do I access changeset data in my HTML, passed in via form: to_form(changeset)
, when not using a Phoenix input
component? Am I really supposed to do this:
<p><%= @form[:foo].value %></p>
Or am I missing something?
Yes. That’s how you get access to the value of the input. It’s not clear if that’s what you’re looking for though.
I have a Changeset it becomes a Form via to_form
which is passed into the template as @form
. For input components I can just use <input field={f[:foo]} ...>
where f
comes from <.form :let={f} for={@form}...
. But if I just want to see the (changed) data in a read-only way what do I use? If I were just passing in the struct/data (not the changeset via a form), I’d use <%= @data.foo %>
, or course.
Another thing I just noticed trying to use .value
, embeds end-up with strings for keys not symbols. So now I have to switch all my my dot syntax to brackets. So what was once @data.foo.bar
is now @form[:foo].value["bar"]
. This just seems goofy.