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

Omit meaningless markup from hidden input in core components #5700

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions installer/templates/phx_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ defmodule <%= @web_namespace %>.CoreComponents do
"""
end

def input(%{type: "hidden"} = assigns) do
~H"""
<input
type="hidden"
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want a {@rest} in here to capture any additional provided attributes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest consists of things that should not be in hidden input as well. At least to my understanding. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing something like form can still be relevant for hidden inputs, therefore rest should be included in my opinion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

"""
end

# All other inputs text, datetime-local, url, password, etc. are handled here...
def input(assigns) do
~H"""
Expand Down
11 changes: 11 additions & 0 deletions priv/templates/phx.gen.live/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ defmodule <%= @web_namespace %>.CoreComponents do
"""
end

def input(%{type: "hidden"} = assigns) do
~H"""
<input
type="hidden"
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
/>
"""
end

# All other inputs text, datetime-local, url, password, etc. are handled here...
def input(assigns) do
~H"""
Expand Down
Loading