Skip to content

Commit 1503137

Browse files
authored
allow structs as param values in used_input? check (#3762)
Closes #3757.
1 parent 09dcbdd commit 1503137

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/phoenix_component.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,10 +1697,17 @@ defmodule Phoenix.Component do
16971697
unused_field_str = "_unused_#{field}"
16981698

16991699
case params do
1700-
%{^field_str => _, ^unused_field_str => _} -> false
1701-
%{^field_str => %{} = nested} -> Enum.any?(Map.keys(nested), &used_param?(nested, &1))
1702-
%{^field_str => _val} -> true
1703-
%{} -> false
1700+
%{^field_str => _, ^unused_field_str => _} ->
1701+
false
1702+
1703+
%{^field_str => %{} = nested} when not is_struct(nested) ->
1704+
Enum.any?(Map.keys(nested), &used_param?(nested, &1))
1705+
1706+
%{^field_str => _val} ->
1707+
true
1708+
1709+
%{} ->
1710+
false
17041711
end
17051712
end
17061713

test/phoenix_component_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,15 @@ defmodule Phoenix.ComponentUnitTest do
335335
"bday" => %{"day" => "", "month" => "", "year" => ""},
336336
"published_at" => %{"date" => "", "time" => "", "_unused_date" => "", "_unused_time" => ""},
337337
"deleted_at" => %{},
338-
"inserted_at" => %{"date" => "", "time" => "", "_unused_time" => ""}
338+
"inserted_at" => %{"date" => "", "time" => "", "_unused_time" => ""},
339+
"date" => DateTime.utc_now()
339340
}
340341

341342
form = to_form(params, as: "profile", action: :validate)
342343
assert used_input?(form[:bday])
343344
refute used_input?(form[:published_at])
344345
refute used_input?(form[:deleted_at])
345346
assert used_input?(form[:inserted_at])
347+
assert used_input?(form[:date])
346348
end
347349
end

0 commit comments

Comments
 (0)