Hi. I ran the live view generator. When I clicked the “New” post button of my newly generated CRUD app, I received a pile of error gobbly goop. I have no idea what is wrong.
I copied the routes to the routes file as prompted.
mix ecto.create
mix ecto.migrate
mix phx.server
When the app launched I went to /boards and I clicked the new button. I got a prompt saying that it couldn’t find the internet and it spat out a big pile of text below. Thank you.
That got rid of the initial error but it looks like a cascade.
This is about a 5th of the blob I currently got. I’ll just leave this here for the next person that stumbles into it. I don’t care to go down this path any further
I’m just bumping into this as well, attempting to use the new phoenix v1.7.0-rc.3 generator.
The problem seems to be the phx.gen.live generator templates haven’t been updated to use the new form stuff (in particular I think I need to call to_form/2 somewhere… just looking into it now). Although it’s nearly bedtime here in Australia so I probably won’t get to fixing it tonight either
The core components have not been updated yet to use the new form structure, so you need to add a new function head for that or call it with {form, field}.
Additionally the table component has not been updated for streams yet. You can pass the data structure to to_param or probably just use elem(row, 0) since that’s should a unique id too.
#core_components.ex:288
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
if assigns.multiple do
# left as an exercise to the reader
raise "FormField x multiple not implemented"
end
assigns
|> assign(field: nil)
|> assign_new(:name, fn -> field.name end)
|> assign_new(:id, fn -> field.id end)
|> assign_new(:value, fn -> field.value end)
|> assign_new(:errors, fn -> translate_errors(field.errors || [], field.field) end)
|> input()
end
# and also in def table
<tr
:for={row <- @rows}
id={"#{@id}-#{Phoenix.Param.to_param(elem(row, 1))}"}
class="relative group hover:bg-zinc-50"
>
I’m not sure if this is the best way to fix, but the key for me was to take all the places that the FormComponent was using a changeset assign, and still get the changeset, but instead use a form assign like so:
assign(socket, form: to_form(changeset))
Then, in your .simple_form function components you can use the @form syntax described here.
you should probably change the title to mention the phoenix version and actual error. so something like “Phoenix 1.7 RC3 :name key not found in forms”.
i’m battling this as well. but i’m trying to migrate my RC2 stuff to RC3. phoenixdiff.org is of some help, but this particular :name thing has got me stumped.
the core of the issue seems to be that the :name field should be generated by def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do in the core_components.ex, but I can’t figure out where the FormField is supposed to originate from so this function is never called. the docs aren’t too helpful to figure out what this is and why. and the Form docs aren’t updated either.
I think overall @benswift’s solution with to_form() is correct, but i’m currently dealing with the login form, which doesn’t seem to have a changeset from phx.gen.auth. i’ll go check if that’s updated.
edit: oh, it is in fact updated. so all in all to_form() is the solution with or without changesets. too bad phoenixdiff.org doesn’t have phx.gen.auth included. would have solved this already.
But then you also need to update your own form code to use the new form syntax as well. It’s quite different. I ended creating a new app from scratch and generating liveviews to try and figure out what the difference was. Here’s what a form_component.ex now looks like. There’s no let={f} on the simple_form for example and individual inputs just take the field={@form[:key]} rather than the old syntax which looked like field={{f, :key}}.