mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-20 07:12:49 +12:00
fix: Fix nested form naming (#14)
This commit is contained in:
parent
429e510b47
commit
c861cc9092
2 changed files with 50 additions and 2 deletions
|
@ -1716,7 +1716,7 @@ defmodule AshPhoenix.Form do
|
||||||
prev_data_trail: prev_data_trail,
|
prev_data_trail: prev_data_trail,
|
||||||
forms: opts[:forms] || [],
|
forms: opts[:forms] || [],
|
||||||
manage_relationship_source: manage_relationship_source(source_changeset, opts),
|
manage_relationship_source: manage_relationship_source(source_changeset, opts),
|
||||||
as: name <> "#{key}][#{index}][",
|
as: name <> "[#{key}][#{index}]",
|
||||||
id: id <> "_#{key}_#{index}"
|
id: id <> "_#{key}_#{index}"
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -303,6 +303,54 @@ defmodule AshPhoenix.FormTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "inputs_for` relationships" do
|
describe "inputs_for` relationships" do
|
||||||
|
test "it should name the fields correctly on `for_update`" do
|
||||||
|
post_id = Ash.UUID.generate()
|
||||||
|
comment_id = Ash.UUID.generate()
|
||||||
|
|
||||||
|
comment = %Comment{
|
||||||
|
text: "text",
|
||||||
|
post: %Post{
|
||||||
|
id: post_id,
|
||||||
|
text: "Some text",
|
||||||
|
comments: [%Comment{id: comment_id}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
form =
|
||||||
|
comment
|
||||||
|
|> Form.for_update(:update,
|
||||||
|
as: "comment",
|
||||||
|
forms: [
|
||||||
|
post: [
|
||||||
|
data: comment.post,
|
||||||
|
type: :single,
|
||||||
|
resource: Post,
|
||||||
|
update_action: :update,
|
||||||
|
create_action: :create,
|
||||||
|
forms: [
|
||||||
|
comments: [
|
||||||
|
data: & &1.comments,
|
||||||
|
type: :list,
|
||||||
|
resource: Comment,
|
||||||
|
update_action: :update,
|
||||||
|
create_action: :create
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
comments_form =
|
||||||
|
form
|
||||||
|
|> form_for("action")
|
||||||
|
|> inputs_for(:post)
|
||||||
|
|> hd()
|
||||||
|
|> inputs_for(:comments)
|
||||||
|
|> hd()
|
||||||
|
|
||||||
|
assert comments_form.name == "comment[post][comments][0]"
|
||||||
|
end
|
||||||
|
|
||||||
test "the `type: :single` option should create a form without integer paths" do
|
test "the `type: :single` option should create a form without integer paths" do
|
||||||
form =
|
form =
|
||||||
Comment
|
Comment
|
||||||
|
@ -560,7 +608,7 @@ defmodule AshPhoenix.FormTest do
|
||||||
inputs_for(form_for(form, "action"), :post)
|
inputs_for(form_for(form, "action"), :post)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "failing single intermediate form" do
|
test "it creates nested forms for single resources" do
|
||||||
post_id = Ash.UUID.generate()
|
post_id = Ash.UUID.generate()
|
||||||
comment_id = Ash.UUID.generate()
|
comment_id = Ash.UUID.generate()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue