Skip to content

Commit 15d0652

Browse files
committed
fix param handling and pass action from form not changeset
1 parent 324b731 commit 15d0652

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

lib/polymorphic_embed/html/helpers.ex

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ if Code.ensure_loaded?(Phoenix.HTML) && Code.ensure_loaded?(Phoenix.HTML.Form) d
4949
form.source.data.__struct__
5050
end
5151

52-
def to_form(%{action: parent_action} = source_changeset, form, field, options) do
52+
def to_form(source_changeset, %{action: parent_action} = form, field, options) do
5353
id = to_string(form.id <> "_#{field}")
5454
name = to_string(form.name <> "[#{field}]")
5555

56-
params = Map.get(source_changeset.params || %{}, to_string(field), %{}) |> List.wrap()
56+
params = Map.get(source_changeset.params || %{}, to_string(field), %{})
5757

5858
struct = Ecto.Changeset.apply_changes(source_changeset)
5959

@@ -71,7 +71,17 @@ if Code.ensure_loaded?(Phoenix.HTML) && Code.ensure_loaded?(Phoenix.HTML.Form) d
7171
list_data
7272
|> Enum.with_index()
7373
|> Enum.map(fn {data, i} ->
74-
params = Enum.at(params, i) || %{}
74+
params =
75+
case params do
76+
nil ->
77+
%{}
78+
79+
params when is_list(params) ->
80+
Enum.at(params, i) || %{}
81+
82+
params when is_map(params) ->
83+
Map.get(params, to_string(i), %{})
84+
end
7585

7686
changeset =
7787
data

0 commit comments

Comments
 (0)