Skip to content

Commit 84dcbdd

Browse files
authored
improvement: Document :params option for for_action (#361)
1 parent 05c08ae commit 84dcbdd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/ash_phoenix/form/form.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ defmodule AshPhoenix.Form do
285285
tenant: [
286286
type: :any,
287287
doc: "The current tenant. Passed through to the underlying action."
288+
],
289+
params: [
290+
type: :any,
291+
default: %{},
292+
doc: """
293+
The initial parameters to use for the form. This is useful for setting up a form with default values.
294+
"""
288295
]
289296
]
290297

test/form_test.exs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ defmodule AshPhoenix.FormTest do
2020

2121
assert 0 =
2222
Post
23-
|> Form.for_action(:post_count, params: params)
23+
|> Form.for_action(:post_count)
2424
|> Form.validate(params)
2525
|> Form.submit!(params: params)
2626
end
27+
28+
test "generic actions can accept initial params" do
29+
params = %{containing: "hello"}
30+
31+
assert 0 =
32+
Post
33+
|> Form.for_action(:post_count, params: params)
34+
|> Form.submit!(params: nil)
35+
end
2736
end
2837

2938
describe "drop_param" do

0 commit comments

Comments
 (0)