Skip to content

Commit 4c76949

Browse files
committed
fix: merge overridden params with original params in code interfaces
fixes #375
1 parent 4716b0f commit 4c76949

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/transformers/add_form_code_interfaces.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule AshPhoenix.Transformers.AddFormCodeInterfaces do
8888
8989
Any *additional* options will be passed to the underlying call to build the source, i.e
9090
`Ash.ActionInput.for_action/4`, or `Ash.Changeset.for_*`. This means you can set things
91-
like the tenant/actor. These will be retained, and provided again when
91+
like the tenant/actor. These will be retained, and provided again when
9292
`Form.submit/3` is called.
9393
9494
## Nested Form Options
@@ -124,7 +124,7 @@ defmodule AshPhoenix.Transformers.AddFormCodeInterfaces do
124124
125125
Any *additional* options will be passed to the underlying call to build the source, i.e
126126
`Ash.ActionInput.for_action/4`, or `Ash.Changeset.for_*`. This means you can set things
127-
like the tenant/actor. These will be retained, and provided again when
127+
like the tenant/actor. These will be retained, and provided again when
128128
`Form.submit/3` is called.
129129
130130
## Nested Form Options
@@ -142,8 +142,8 @@ defmodule AshPhoenix.Transformers.AddFormCodeInterfaces do
142142
|> unquote(__MODULE__).set_private_arguments(unquote(private_args_merge))
143143

144144
AshPhoenix.Form.for_action(unquote(resource), unquote(action.name), form_opts)
145-
|> Map.put(:params, unquote(merge_params))
146-
|> Map.put(:raw_params, unquote(merge_params))
145+
|> Map.update!(:params, &Map.merge(&1, unquote(merge_params)))
146+
|> Map.update!(:raw_params, &Map.merge(&1, unquote(merge_params)))
147147
end
148148
end
149149

test/ash_phoenix_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,18 @@ defmodule AshPhoenixTest do
2222
assert %AshPhoenix.Form{data: %{id: ^id}} =
2323
AshPhoenix.Test.Domain.form_to_update_user(%AshPhoenix.Test.User{id: id})
2424
end
25+
26+
test "adding a form retains original params" do
27+
form =
28+
AshPhoenix.Test.Domain.form_to_create_post(
29+
params: %{"text" => "original text", "title" => "original title"}
30+
)
31+
32+
assert AshPhoenix.Form.value(form, :text) == "original text"
33+
34+
form =
35+
AshPhoenix.Form.add_form(form, :comments, params: %{"text" => "new comment"})
36+
37+
assert AshPhoenix.Form.value(form, :text) == "original text"
38+
end
2539
end

test/support/domain.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ defmodule AshPhoenix.Test.Domain do
1515
define_calculation :always_true
1616
end
1717

18+
resource AshPhoenix.Test.Post do
19+
define :create_post, action: :create
20+
end
21+
1822
resource(AshPhoenix.Test.DeepNestedUnionResource)
1923
resource(AshPhoenix.Test.SimplePost)
2024
end

0 commit comments

Comments
 (0)