From 33e14df05b242808e78c76f7911e797aa38f654d Mon Sep 17 00:00:00 2001 From: iyjim Date: Sun, 11 May 2025 17:30:15 +0800 Subject: [PATCH 1/5] Add a generic action form test in form_test.exs Form.for_action() needs initial params like Form.for_create() does, so add this test to ensure this feature work. --- test/form_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/form_test.exs b/test/form_test.exs index f60ac69..8ccdb60 100644 --- a/test/form_test.exs +++ b/test/form_test.exs @@ -24,6 +24,15 @@ defmodule AshPhoenix.FormTest do |> Form.validate(params) |> Form.submit!(params: params) end + + test "generic actions can have forms with initial params" do + params = %{containing: "hello"} + + assert 0 = + Post + |> Form.for_action(:post_count, params: params) + |> Form.submit!(params: params) + end end describe "drop_param" do From a2c72bcef54ec781236c5ef736b0ff2c9df50b2c Mon Sep 17 00:00:00 2001 From: iyjim Date: Mon, 12 May 2025 21:18:34 +0800 Subject: [PATCH 2/5] add :params document and fix 'for_action()'s :params option' issue 1. Add :params document for all for_* actions. 2. Fix 'for_action() doesn't accept :params option' issue --- lib/ash_phoenix/form/form.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ash_phoenix/form/form.ex b/lib/ash_phoenix/form/form.ex index c050652..6d02cf8 100644 --- a/lib/ash_phoenix/form/form.ex +++ b/lib/ash_phoenix/form/form.ex @@ -285,6 +285,13 @@ defmodule AshPhoenix.Form do tenant: [ type: :any, doc: "The current tenant. Passed through to the underlying action." + ], + params: [ + type: :any, + default: %{}, + doc: """ + The initial parameters to use for the form. This is useful for setting up a form with default values. + """ ] ] @@ -6001,7 +6008,8 @@ defmodule AshPhoenix.Form do :transform_params, :prepare_params, :prepare_source, - :warn_on_unhandled_errors? + :warn_on_unhandled_errors?, + :params ]) end end From cec6937285b2a9a3c732709807e73aa089a5bb70 Mon Sep 17 00:00:00 2001 From: iyjim Date: Mon, 12 May 2025 21:22:09 +0800 Subject: [PATCH 3/5] Tune the test added yesterday --- test/form_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/form_test.exs b/test/form_test.exs index 8ccdb60..024869e 100644 --- a/test/form_test.exs +++ b/test/form_test.exs @@ -25,13 +25,13 @@ defmodule AshPhoenix.FormTest do |> Form.submit!(params: params) end - test "generic actions can have forms with initial params" do + test "generic actions can accept initial params" do params = %{containing: "hello"} assert 0 = Post |> Form.for_action(:post_count, params: params) - |> Form.submit!(params: params) + |> Form.submit!(params: %{}) end end From 6c177fb6ed34e6d5b98bfc7fd4cc0b5fb02f0fce Mon Sep 17 00:00:00 2001 From: iyjim Date: Tue, 13 May 2025 09:09:18 +0800 Subject: [PATCH 4/5] Remove duplicate :params item in drop_drom_opts() function --- lib/ash_phoenix/form/form.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ash_phoenix/form/form.ex b/lib/ash_phoenix/form/form.ex index c280210..cd78cba 100644 --- a/lib/ash_phoenix/form/form.ex +++ b/lib/ash_phoenix/form/form.ex @@ -6009,8 +6009,7 @@ defmodule AshPhoenix.Form do :transform_params, :prepare_params, :prepare_source, - :warn_on_unhandled_errors?, - :params + :warn_on_unhandled_errors? ]) end end From fa362728a2f86b248750a9287030f762c8400d8a Mon Sep 17 00:00:00 2001 From: iyjim Date: Tue, 13 May 2025 09:20:11 +0800 Subject: [PATCH 5/5] Update generic actions tests --- test/form_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/form_test.exs b/test/form_test.exs index fcea796..1f52a59 100644 --- a/test/form_test.exs +++ b/test/form_test.exs @@ -20,7 +20,7 @@ defmodule AshPhoenix.FormTest do assert 0 = Post - |> Form.for_action(:post_count, params: params) + |> Form.for_action(:post_count) |> Form.validate(params) |> Form.submit!(params: params) end @@ -31,7 +31,7 @@ defmodule AshPhoenix.FormTest do assert 0 = Post |> Form.for_action(:post_count, params: params) - |> Form.submit!(params: %{}) + |> Form.submit!(params: nil) end end