Handling an %Ash.Error.Invalid{} in LiveView
Sorry for the noob question, but the AshPhoenix guide doesn't show any error handling.
This is the code that I assumed would work, but update returns a
{:error, %Ash.Error.Invalid{} }
How do I get those errors onto the form?
7 Replies
You should use
AshPhoenix.Form
to get good error handling in forms
Have you looked through the examples of how to use AshPhoenix.Form
?
A recent good example project using them was shared in the #showcase channelLooking now...
Did you create a form for the update slug work that you're doing?
Because your
handle_event
there should look something like this if implemented correctly:
I created a form like this...
Gotcha, so now you need to submit that form
What you're currently doing is getting the current account and calling the
update
logic on it directly
but you should use AshPhoenix.Form.submit(socket.assigns.slug_form, params: params)
to submit it
then you'd get {:error, form}
back from the error caseGot it
Thanks for the help!
Happy to help!