Fix ammo group create form error bug

This commit is contained in:
2022-03-04 23:16:37 -05:00
parent 9f2cc54738
commit 8bb4aab49c
4 changed files with 36 additions and 26 deletions

View File

@ -36,10 +36,23 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
def handle_event(
"validate",
%{"ammo_group" => ammo_group_params},
%{assigns: %{ammo_group: ammo_group}} = socket
%{assigns: %{action: action, ammo_group: ammo_group}} = socket
) do
socket = socket |> assign(:changeset, ammo_group |> Ammo.change_ammo_group(ammo_group_params))
{:noreply, socket}
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset = ammo_group |> Ammo.change_ammo_group(ammo_group_params)
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
{:noreply, socket |> assign(:changeset, changeset)}
end
def handle_event(
@ -142,9 +155,6 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)
{:error, nil} ->
socket
end
end
end

View File

@ -69,6 +69,7 @@
) %>
<%= error_tag(f, :multiplier, "col-span-3 text-center") %>
<% :edit -> %>
<%= submit(dgettext("actions", "Save"),
phx_disable_with: dgettext("prompts", "Saving..."),