How to use AshPhoenix.Form with the default core_components file that comes with Phoenix 1.7?
Phoenix 1.7 has updated the core_components file that comes with
mix phx.new
which means we need to change the way we use AshPhoenix.Form
to play nicely with the updated form components.
From what I gathered in some of the previous conversations, the way to do it in the new component should be as follows.
When calling <.simple_form />
, the :let
should removed so it would look like this:
When it comes to using <.input />
, the field
attribute should look like this:
When defining the form, we can still use the regular AshPhoenix.Form.for_action
, AshPhoenix.Form.for_create
, and AshPhoenix.Form.for_update
and then calling to_form()
to make it compliant with the new components.
When calling the validate handle_event
, there are no issues with just assigning AshPhoenix.Form.validate() |> to_form()
for the form assigns in the socket.
My problem is with calling AshPhoenix.Form.submit
. I am getting an error when doing the following:
I am getting the following error:
What should I do to fix this? For some reason, it actually persists in the database. It's just that I'm getting this error if I call the line above.
I am using ash_phoenix
1.2.85 Replies
I'm just guessing here. I'm looking at the source for
AshPhoenix.Form.submit
and it looks like submit/2
is returning {:ok, Ash.Resource.record()}
which breaks the call to Phoenix.HTML.FormData.to_form/1
.
I'm not 100% and it's just based on how I understood the source code for this.
https://github.com/ash-project/ash_phoenix/blob/v1.2.8/lib/ash_phoenix/form/form.ex#L1434GitHub
ash_phoenix/form.ex at v1.2.8 · ash-project/ash_phoenix
https://hexdocs.pm/ash_phoenix. Contribute to ash-project/ash_phoenix development by creating an account on GitHub.
I forked
ash_phoenix
and I did some testing. My guess was correct - submit/2
was indeed returning {:ok, Ash.Resource.record()}
so the call to Phoenix.HTML.FormData.to_form/1
will not work.
I'm not sure if I just did it wrong or if this is an actual bug.pretty sure you should keep the :let={f} and use that
no need to call to_form manually

That worked! I realized I was wrong because I was trying to follow the way the new generators in 1. 7 did it. Apparently, all I had to do was update
ash_phoenix
to the latest version. and that was it.
Thanks!