%Ash.Error.Changes.Required{
Another newbie question.. AshPhoenix.Form.submit is failing with this error message. Below are the related codes.
The issue seems to be due to the fact that the new email address is not added to arguments.
<error message>
iex(16)> [debug] HANDLE EVENT
View: MyAppWeb.UserLive.UserSettings
Event: "update_email"
Parameters: %{"current_password" => "[FILTERED]", "form" => %{"email" => "[email protected]"}}
iex(16)> : #Ash.Changeset<
action_type: :update,
action: :change_user_email,
attributes: %{},
relationships: %{},
arguments: %{current_password: "pwd12345"},
errors: [ %Ash.Error.Changes.Required{ field: :email, type: :argument, resource: MyApp.Accounts.User, changeset: nil, query: nil, <mount> |> assign( :email_form, AshPhoenix.Form.for_update(current_user, :change_user_email, api: MyApp.Accounts, actor: current_user ) ) <handle event> def handle_event("update_email", params, socket) do case AshPhoenix.Form.submit(socket.assigns.email_form, params: params) do {:ok, _result} -> { :noreply, socket |> put_flash(:info, "Email changed successfully!") # |> push_navigate(to: socket.assigns.navigate) } <resource action> update :change_user_email do argument :email, :string do allow_nil? false end argument :current_password, :string do allow_nil? true end change {RequirePasswordConfirmation, password: :current_password} change set_attribute(:email, arg(:email)) end
errors: [ %Ash.Error.Changes.Required{ field: :email, type: :argument, resource: MyApp.Accounts.User, changeset: nil, query: nil, <mount> |> assign( :email_form, AshPhoenix.Form.for_update(current_user, :change_user_email, api: MyApp.Accounts, actor: current_user ) ) <handle event> def handle_event("update_email", params, socket) do case AshPhoenix.Form.submit(socket.assigns.email_form, params: params) do {:ok, _result} -> { :noreply, socket |> put_flash(:info, "Email changed successfully!") # |> push_navigate(to: socket.assigns.navigate) } <resource action> update :change_user_email do argument :email, :string do allow_nil? false end argument :current_password, :string do allow_nil? true end change {RequirePasswordConfirmation, password: :current_password} change set_attribute(:email, arg(:email)) end
11 Replies
This looks incorrect
Do things you want to change here
get the fields out of the
"form"
key
and then additionally you want to not override the id of the current_password
field
or the name
or if you do the name needs to be form[current_password]
Sorry I don't quite follow. In your second point, do you mean the id and name should be "current_password" like this?
<.input
field={{f, :current_password}}
name="current_password"
id="current_password"
type="password"
label="Current password"
value={@email_form_current_password}
required
/>
Just remove
name
and id
from that
šThat fixed this part Parameters: %{"form" => %{"current_password" => "[FILTERED]", "email" => "[email protected]"}}
But this still happens. You said "Do things you want to change here" but I'm not sure what needs to change there.
#Ash.Changeset<
action_type: :update,
action: :change_user_email,
attributes: %{},
relationships: %{},
arguments: %{},
errors: [
%Ash.Error.Changes.Required{
field: :email,
type: :argument,
resource: MyApp.Accounts.User,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
can I see your current submit logic?
You mean something other than the action or handle event definitions that are above?
I mean your
handle_event
that does the submission. Did you change it the way I suggested?No, sorry, I'm not sure what change needs to be made. I have another Form.submit for user_timezone that works well with codes that look just like this one, so I could use some pointers as to how to change this one.
Your original code shows this
but the form params are nested in the
"form"
key
so you need to pull them outoh.. I missed that. Thanks. That fixed it. š
š„³