add changeset_errors/1 helper to form components
This commit is contained in:
@ -17,12 +17,7 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
|
||||
@impl true
|
||||
def handle_event("validate", %{"container" => container_params}, socket) do
|
||||
container_params = container_params |> Map.put("user_id", socket.assigns.current_user.id)
|
||||
|
||||
changeset =
|
||||
socket.assigns.container
|
||||
|> Containers.change_container(container_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
changeset = socket.assigns.container |> Containers.change_container(container_params)
|
||||
{:noreply, socket |> assign(:changeset, changeset)}
|
||||
end
|
||||
|
||||
@ -47,40 +42,42 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
<%= if @changeset.action do %>
|
||||
<div class="invalid-feedback col-span-3 text-center">
|
||||
<%= changeset_errors(@changeset) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label(f, :name, class: "title text-lg text-primary-500") %>
|
||||
<%= text_input(f, :name,
|
||||
class: "input input-primary col-span-2",
|
||||
placeholder: "My cool ammo can"
|
||||
) %>
|
||||
<span class="col-span-3">
|
||||
<%= error_tag(f, :name) %>
|
||||
</span>
|
||||
<%= error_tag(f, :name, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :desc, class: "title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :desc,
|
||||
class: "input input-primary col-span-2",
|
||||
phx_hook: "MaintainAttrs",
|
||||
placeholder: "Metal ammo can with the anime girl sticker"
|
||||
) %>
|
||||
<span class="col-span-3">
|
||||
<%= error_tag(f, :desc) %>
|
||||
</span>
|
||||
<%= error_tag(f, :desc, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :type, class: "title text-lg text-primary-500") %>
|
||||
<%= text_input(f, :type,
|
||||
class: "input input-primary col-span-2",
|
||||
placeholder: "Magazine, Clip, Ammo Box, etc"
|
||||
) %>
|
||||
<span class="col-span-3">
|
||||
<%= error_tag(f, :type) %>
|
||||
</span>
|
||||
<%= error_tag(f, :type, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :location, class: "title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :location,
|
||||
class: "input input-primary col-span-2",
|
||||
phx_hook: "MaintainAttrs",
|
||||
placeholder: "On the bookshelf"
|
||||
) %>
|
||||
<span class="col-span-3">
|
||||
<%= error_tag(f, :location) %>
|
||||
</span>
|
||||
<%= error_tag(f, :location, "col-span-3 text-center") %>
|
||||
|
||||
<%= submit("Save",
|
||||
class: "mx-auto btn btn-primary col-span-3",
|
||||
phx_disable_with: "Saving..."
|
||||
|
Reference in New Issue
Block a user