Skip to content

Commit

Permalink
Allow <.input type="checkbox"> without value attr in core compone…
Browse files Browse the repository at this point in the history
…nts (#5427)

* Allow `<.input type="checkbox">` without `value` attr in core components

* Fix typo on assigns
  • Loading branch information
gorghoa authored Oct 3, 2023
1 parent 495a18d commit 2c7fa8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions installer/templates/phx_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ defmodule <%= @web_namespace %>.CoreComponents do
|> input()
end

def input(%{type: "checkbox", value: value} = assigns) do
def input(%{type: "checkbox"} = assigns) do
assigns =
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", value) end)
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value]) end)

~H"""
<div phx-feedback-for={@name}>
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.live/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ defmodule <%= @web_namespace %>.CoreComponents do
|> input()
end

def input(%{type: "checkbox", value: value} = assigns) do
def input(%{type: "checkbox"} = assigns) do
assigns =
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", value) end)
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value]) end)

~H"""
<div phx-feedback-for={@name}>
Expand Down

0 comments on commit 2c7fa8e

Please sign in to comment.