fix: always pass forms down

This commit is contained in:
Zach Daniel 2021-07-17 16:06:15 -04:00
parent 785263e514
commit f36e6c30f2
3 changed files with 22 additions and 28 deletions

View file

@ -1317,11 +1317,19 @@ defmodule AshPhoenix.Form do
if data do if data do
if (opts[:type] || :single) == :single do if (opts[:type] || :single) == :single do
for_update(data, update_action, errors: error?, prev_data_trail: prev_data_trail) for_update(data, update_action,
errors: error?,
prev_data_trail: prev_data_trail,
forms: opts[:forms] || []
)
else else
Enum.map( Enum.map(
data, data,
&for_update(&1, update_action, errors: error?, prev_data_trail: prev_data_trail) &for_update(&1, update_action,
errors: error?,
prev_data_trail: prev_data_trail,
forms: opts[:forms] || []
)
) )
end end
else else

View file

@ -5,7 +5,7 @@ defmodule AshPhoenix.Form.NoDataLoaded do
%__MODULE__{path: opts[:path]} %__MODULE__{path: opts[:path]}
end end
def message(%{action: :update, path: path}) do def message(%{path: path}) do
""" """
Data was not loaded when using a function to determine data at path: #{inspect(path)}. Data was not loaded when using a function to determine data at path: #{inspect(path)}.
If you pass a function to the `data` option, you need to either If you pass a function to the `data` option, you need to either
@ -42,27 +42,4 @@ defmodule AshPhoenix.Form.NoDataLoaded do
) )
""" """
end end
def message(%{action: :create, path: path}) do
"""
The `data` key was configured for #{inspect(path)}, but no `update_action` was configured. Please configure one.
For example:
Form.for_create(
Resource,
:action,
params,
forms: [
# For forms over existing data
form_name: [
type: :list,
as: "form_name",
data: data,
resource: RelatedResource,
update_action: :update_or_destroy_action_name
]
]
)
"""
end
end end

View file

@ -555,7 +555,16 @@ defmodule AshPhoenix.FormTest do
test "failing single intermediate form" do test "failing single intermediate form" do
post_id = Ash.UUID.generate() post_id = Ash.UUID.generate()
comment = %Comment{text: "text", post: %Post{id: post_id, text: "Some text"}} comment_id = Ash.UUID.generate()
comment = %Comment{
text: "text",
post: %Post{
id: post_id,
text: "Some text",
comments: [%Comment{id: comment_id}]
}
}
form = form =
comment comment
@ -580,7 +589,7 @@ defmodule AshPhoenix.FormTest do
] ]
) )
assert [%Phoenix.HTML.Form{source: %AshPhoenix.Form{resource: AshPhoenix.Test.Post}}] = assert [%Phoenix.HTML.Form{source: %AshPhoenix.Form{resource: AshPhoenix.Test.Comment}}] =
form form
|> form_for("action") |> form_for("action")
|> inputs_for(:post) |> inputs_for(:post)