Hi all,
I am seeing form errors while a live view is loading. Then they disappear.
I am using a vanilla Phoenix project with tailwind and core components to render the form.
You can see the source code at:
GitHub - carlotm/form-errors-are-visible
Is this behaviour intended/known, or am I doing something wrong here?
Cheers!
It’s because you’re setting an action:
end
def handle_event("validate", %{"project" => params}, socket) do
form = build_form(params)
{:noreply, assign(socket, form: build_form(params))}
end
defp build_form(params \\ %{}) do
%Project{}
|> Project.changeset(params)
|> Map.put(:action, :validate)
|> to_form()
end
end
You don’t want to set an action on a changeset until you are ready to display errors like in a validate or submit callback
To just build the form, you can remove that line
I would move that line to the validate callback
2 Likes
Thank you, it was indeed the reason!