Skip to content

Commit

Permalink
No need to track id
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Feb 5, 2024
1 parent 5f6e91a commit f7bd1f6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
5 changes: 1 addition & 4 deletions lib/phoenix_html/form.ex
Expand Up @@ -65,7 +65,6 @@ defmodule Phoenix.HTML.Form do
name: nil,
data: nil,
action: nil,
method: nil,
hidden: [],
params: %{},
errors: [],
Expand All @@ -77,7 +76,6 @@ defmodule Phoenix.HTML.Form do
name: String.t(),
data: %{field => term},
action: nil | atom() | String.t(),
method: nil | atom() | String.t(),
params: %{binary => term},
hidden: Keyword.t(),
options: Keyword.t(),
Expand Down Expand Up @@ -196,7 +194,7 @@ defmodule Phoenix.HTML.Form do
Receives two forms structs and checks if the given field changed.
The field will have changed if either its associated value, errors,
action, method, or implementation changed. This is mostly used for optimization
action, or implementation changed. This is mostly used for optimization
engines as an extension of the `Access` behaviour.
"""
@spec input_changed?(t, t, field()) :: boolean()
Expand All @@ -207,7 +205,6 @@ defmodule Phoenix.HTML.Form do
)
when is_atom(field) or is_binary(field) do
impl1 != impl2 or id1 != id2 or name1 != name2 or form1.action != form2.action or
form1.method != form2.method or
field_errors(errors1, field) != field_errors(errors2, field) or
impl1.input_value(source1, form1, field) != impl2.input_value(source2, form2, field)
end
Expand Down
7 changes: 0 additions & 7 deletions lib/phoenix_html/form_data.ex
Expand Up @@ -58,8 +58,6 @@ defprotocol Phoenix.HTML.FormData do
* `:action` - The form action, such as the HTML `action` attribute
or LiveView action.
* `:method` - The form method, such as the HTML `method` attribute.
"""
@spec to_form(t, Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field(), Keyword.t()) ::
[Phoenix.HTML.Form.t()]
Expand All @@ -84,7 +82,6 @@ defimpl Phoenix.HTML.FormData, for: Map do
{name, params, opts} = name_params_and_opts(conn_or_atom_or_map, opts)
{errors, opts} = Keyword.pop(opts, :errors, [])
{action, opts} = Keyword.pop(opts, :action, nil)
{method, opts} = Keyword.pop(opts, :method, nil)
id = Keyword.get(opts, :id) || name

unless is_binary(id) or is_nil(id) do
Expand All @@ -100,7 +97,6 @@ defimpl Phoenix.HTML.FormData, for: Map do
data: %{},
errors: errors,
action: action,
method: method,
options: opts
}
end
Expand All @@ -127,7 +123,6 @@ defimpl Phoenix.HTML.FormData, for: Map do
{id, opts} = Keyword.pop(opts, :id)
{hidden, opts} = Keyword.pop(opts, :hidden, [])
{action, opts} = Keyword.pop(opts, :action)
{method, opts} = Keyword.pop(opts, :method)

id = to_string(id || form.id <> "_#{field}")
name = to_string(name || form.name <> "[#{field}]")
Expand All @@ -144,7 +139,6 @@ defimpl Phoenix.HTML.FormData, for: Map do
name: name,
data: default,
action: action,
method: method,
params: params || %{},
hidden: hidden,
options: opts
Expand All @@ -170,7 +164,6 @@ defimpl Phoenix.HTML.FormData, for: Map do
impl: __MODULE__,
index: index,
action: action,
method: method,
id: id <> "_" <> index_string,
name: name <> "[" <> index_string <> "]",
data: data,
Expand Down
5 changes: 2 additions & 3 deletions test/phoenix_html/form_test.exs
Expand Up @@ -139,10 +139,9 @@ defmodule Phoenix.HTML.FormTest do
end

test "input_changed? with changed action or method" do
form = form(%{}, action: :validate, method: "post")
refute input_changed?(form, %{form | action: :validate, method: "post"}, :foo)
form = form(%{}, action: :validate)
refute input_changed?(form, %{form | action: :validate}, :foo)
assert input_changed?(form, %{form | action: :save}, :foo)
assert input_changed?(form, %{form | method: "put"}, :foo)
end

describe "access" do
Expand Down

0 comments on commit f7bd1f6

Please sign in to comment.