Ash FrameworkAF
Ash Framework6mo ago
33 replies
Joan Gavelán

How can I show all validation errors (including nested) at once?

I'm using manage_relationship/4 in a top-level action that accepts nested fields via arguments. Right now, the nested validation errors only show after the top-level data is valid. Is there a way to surface all validation errors (parent + nested) simultaneously? I'd like users to see everything in one go
Solution
If you have time to make a PR, what needs to happen is something like this:

form
|> AshPhoenix.Form.raw_errors(for_path: :all)
|> Enum.flat_map(fn {path, errors} ->
  Enum.map(errors, &Ash.Error.set_path(&1, path))
end)
|> to_errors(message_func)
Was this page helpful?