forked from shibao/cannery
use sidecar templates
This commit is contained in:
@ -44,70 +44,6 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
|
||||
save_ammo_group(socket, action, ammo_group_params)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<h2 class="text-center title text-xl text-primary-500">
|
||||
<%= @title %>
|
||||
</h2>
|
||||
<.form
|
||||
let={f}
|
||||
for={@changeset}
|
||||
id="ammo_group-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||
>
|
||||
<%= if @changeset.action do %>
|
||||
<div class="invalid-feedback col-span-3 text-center">
|
||||
<%= changeset_errors(@changeset) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= select(f, :ammo_type_id, ammo_type_options(@ammo_types),
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :ammo_type_id, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :count, gettext("Count"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :count,
|
||||
class: "text-center col-span-2 input input-primary",
|
||||
min: 1
|
||||
) %>
|
||||
<%= error_tag(f, :count, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :price_paid, gettext("Price paid"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :price_paid,
|
||||
step: "0.01",
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :notes, gettext("Notes"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :notes,
|
||||
class: "text-center col-span-2 input input-primary",
|
||||
phx_hook: "MaintainAttrs"
|
||||
) %>
|
||||
<%= error_tag(f, :notes, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :container, gettext("Container"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= select(f, :container_id, container_options(@containers),
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :container_id, "col-span-3 text-center") %>
|
||||
|
||||
<%= submit(dgettext("actions", "Save"),
|
||||
phx_disable_with: dgettext("prompts", "Saving..."),
|
||||
class: "mx-auto col-span-3 btn btn-primary"
|
||||
) %>
|
||||
</.form>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
# HTML Helpers
|
||||
@spec container_options([Container.t()]) :: [{String.t(), Container.id()}]
|
||||
defp container_options(containers) do
|
||||
|
@ -0,0 +1,59 @@
|
||||
<div>
|
||||
<h2 class="text-center title text-xl text-primary-500">
|
||||
<%= @title %>
|
||||
</h2>
|
||||
|
||||
<.form
|
||||
let={f}
|
||||
for={@changeset}
|
||||
id="ammo_group-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||
>
|
||||
<%= if @changeset.action do %>
|
||||
<div class="invalid-feedback col-span-3 text-center">
|
||||
<%= changeset_errors(@changeset) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= select(f, :ammo_type_id, ammo_type_options(@ammo_types),
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :ammo_type_id, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :count, gettext("Count"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :count,
|
||||
class: "text-center col-span-2 input input-primary",
|
||||
min: 1
|
||||
) %>
|
||||
<%= error_tag(f, :count, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :price_paid, gettext("Price paid"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :price_paid,
|
||||
step: "0.01",
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :notes, gettext("Notes"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :notes,
|
||||
class: "text-center col-span-2 input input-primary",
|
||||
phx_hook: "MaintainAttrs"
|
||||
) %>
|
||||
<%= error_tag(f, :notes, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :container, gettext("Container"), class: "mr-4 title text-lg text-primary-500") %>
|
||||
<%= select(f, :container_id, container_options(@containers),
|
||||
class: "text-center col-span-2 input input-primary"
|
||||
) %>
|
||||
<%= error_tag(f, :container_id, "col-span-3 text-center") %>
|
||||
|
||||
<%= submit(dgettext("actions", "Save"),
|
||||
phx_disable_with: dgettext("prompts", "Saving..."),
|
||||
class: "mx-auto col-span-3 btn btn-primary"
|
||||
) %>
|
||||
</.form>
|
||||
</div>
|
Reference in New Issue
Block a user