Ash FrameworkAF
Ash Framework3y ago
22 replies
Jason

%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" => "email5@gmail.com"}}
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
Was this page helpful?