AE
Ash Elixir•3y ago
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" => "[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
11 Replies
ZachDaniel
ZachDaniel•3y ago
This looks incorrect
Parameters: %{"current_password" => "[FILTERED]", "form" => %{"email" => "[email protected]"}}
Parameters: %{"current_password" => "[FILTERED]", "form" => %{"email" => "[email protected]"}}
Do things you want to change here
def handle_event("update_email", %{"form" => 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)
}
def handle_event("update_email", %{"form" => 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)
}
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]
Jason
JasonOP•3y ago
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 />
ZachDaniel
ZachDaniel•3y ago
Just remove name and id from that šŸ™‚
Jason
JasonOP•3y ago
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 }
ZachDaniel
ZachDaniel•3y ago
can I see your current submit logic?
Jason
JasonOP•3y ago
You mean something other than the action or handle event definitions that are above?
ZachDaniel
ZachDaniel•3y ago
I mean your handle_event that does the submission. Did you change it the way I suggested?
Jason
JasonOP•3y ago
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.
ZachDaniel
ZachDaniel•3y ago
def handle_event("update_email", params, socket) do
def handle_event("update_email", params, socket) do
Your original code shows this
def handle_event("update_email", %{"form" => params}, socket) do
def handle_event("update_email", %{"form" => params}, socket) do
but the form params are nested in the "form" key so you need to pull them out
Jason
JasonOP•3y ago
oh.. I missed that. Thanks. That fixed it. šŸ™‚
ZachDaniel
ZachDaniel•3y ago
🄳

Did you find this page helpful?