Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core components to support multiple=true on checkbox inputs #6111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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