I have a nested form based on a resource, Task, that has_many
:keydates. The nested keydate_form has an argument as a virtual field whose validation error (via add_error
) is not being displayed nor does it stop the form submission. error_path
was added to the change manage_relationship
statement as suggested by the Ash documentation, but it doesn’t seem to help. What am I missing?
Form in mount()
form =
AshPhoenix.Form.for_update(task, :update,
forms: [
auto?: true
]
Heex
<.input
field={{@keydate_form, :argument1}}
type="text"
label=""
/>
Task resource
actions do
update :update do
...
argument :keydates, {:array, :map}
change manage_relationship(:keydates, type: :direct_control, **error_path: :keydates**)
end
Keydate resource
actions do
update :update do
change fn changeset, %{actor: actor} ->
Ash.Changeset.before_action(changeset, fn changeset ->
Ash.Changeset.add_error(changeset, [field: :argument1, message: "Input not valid."])
end)
end
Changeset in Form submission error (excerpt)
...,
arguments: %{
keydates: [
%{
"argument1" => "123",
...
}
]}
errors: [
%Ash.Error.Changes.InvalidAttribute{
field: :argument1,
message: "Input not valid.",
private_vars: nil,
value: nil,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
],