From f36e6c30f24cad37e7c1f7a2980b5063e80aa49c Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sat, 17 Jul 2021 16:06:15 -0400 Subject: [PATCH] fix: always pass forms down --- lib/ash_phoenix/form/form.ex | 12 ++++++++++-- lib/ash_phoenix/form/no_data_loaded.ex | 25 +------------------------ test/form_test.exs | 13 +++++++++++-- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/ash_phoenix/form/form.ex b/lib/ash_phoenix/form/form.ex index 2d1d503..282c218 100644 --- a/lib/ash_phoenix/form/form.ex +++ b/lib/ash_phoenix/form/form.ex @@ -1317,11 +1317,19 @@ defmodule AshPhoenix.Form do if data 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 Enum.map( 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 else diff --git a/lib/ash_phoenix/form/no_data_loaded.ex b/lib/ash_phoenix/form/no_data_loaded.ex index 3b5aad6..c017815 100644 --- a/lib/ash_phoenix/form/no_data_loaded.ex +++ b/lib/ash_phoenix/form/no_data_loaded.ex @@ -5,7 +5,7 @@ defmodule AshPhoenix.Form.NoDataLoaded do %__MODULE__{path: opts[:path]} 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)}. If you pass a function to the `data` option, you need to either @@ -42,27 +42,4 @@ defmodule AshPhoenix.Form.NoDataLoaded do ) """ 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 diff --git a/test/form_test.exs b/test/form_test.exs index c52f9d7..a0b97f9 100644 --- a/test/form_test.exs +++ b/test/form_test.exs @@ -555,7 +555,16 @@ defmodule AshPhoenix.FormTest do test "failing single intermediate form" do 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 = 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_for("action") |> inputs_for(:post)