Skip to content

Commit

Permalink
Update core components to support multiple=true on checkbox inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtimberlake committed Mar 4, 2025
1 parent 443104c commit 285846d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions installer/templates/phx_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select and checkbox inputs"

attr :rest, :global,
include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength
Expand All @@ -251,12 +251,12 @@ defmodule <%= @web_namespace %>.CoreComponents do
~H"""
<div>
<label class="flex items-center gap-4 text-sm leading-6 text-zinc-600">
<input type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
<input :if={!@multiple} type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
<input
type="checkbox"
id={@id}
id={if @multiple, do: @id <> "-#{@value}", else: @id}
name={@name}
value="true"
value={if @multiple, do: @value, else: "true"}
checked={@checked}
class="rounded border-zinc-300 text-zinc-900 focus:ring-0"
{@rest}
Expand Down
8 changes: 4 additions & 4 deletions priv/templates/phx.gen.live/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select and checkbox inputs"

attr :rest, :global,
include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength
Expand All @@ -251,12 +251,12 @@ defmodule <%= @web_namespace %>.CoreComponents do
~H"""
<div>
<label class="flex items-center gap-4 text-sm leading-6 text-zinc-600">
<input type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
<input :if={!@multiple} type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
<input
type="checkbox"
id={@id}
id={if @multiple, do: @id <> "-#{@value}", else: @id}
name={@name}
value="true"
value={if @multiple, do: @value, else: "true"}
checked={@checked}
class="rounded border-zinc-300 text-zinc-900 focus:ring-0"
{@rest}
Expand Down

0 comments on commit 285846d

Please sign in to comment.