# Create form and add author sub-form with default value for email
form =
AshPhoenix.Form.for_create(Post, :create, forms: [auto?: true])
|> AshPhoenix.Form.add_form(:author,
params: %{
"email" => "example@email.org"
}
)
# Use update form to update the email of the author
form =
AshPhoenix.Form.update_form(form, :author, fn author_form ->
AshPhoenix.Form.update_params(author_form, fn params ->
Map.put(params, "email", "changed@email.org")
end)
end)
assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "changed@email.org"
# Now update some other attributes on the root form
form =
AshPhoenix.Form.update_params(form, fn params ->
Map.put(params, "text", "text value")
end, only_touched?: true, target: ["text"])
# This fails
assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "changed@email.org"
# Create form and add author sub-form with default value for email
form =
AshPhoenix.Form.for_create(Post, :create, forms: [auto?: true])
|> AshPhoenix.Form.add_form(:author,
params: %{
"email" => "example@email.org"
}
)
# Use update form to update the email of the author
form =
AshPhoenix.Form.update_form(form, :author, fn author_form ->
AshPhoenix.Form.update_params(author_form, fn params ->
Map.put(params, "email", "changed@email.org")
end)
end)
assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "changed@email.org"
# Now update some other attributes on the root form
form =
AshPhoenix.Form.update_params(form, fn params ->
Map.put(params, "text", "text value")
end, only_touched?: true, target: ["text"])
# This fails
assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "changed@email.org"