nallwhy
I’m trying to use AshPhoenix.Form.add_error/3 to add custom validation errors after running some custom logic, but I’m struggling to figure out how to use it correctly. There are no tests or clear examples available, so I’m experimenting with different approaches, but none seem to work as expected.
Here’s what I’m facing:
• If I try to pass a string as the error, I get a warning saying that Ash.Error.Unknown does not implement AshPhoenix.FormData.Error.
• If I manually create an Ash.Error.Changes.InvalidAttribute and pass it in, it gets wrapped in Ash.Error.Invalid. However, when I call AshPhoenix.Form.errors/3, the error does not show up.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
indiosmo
What are you calling add_error/3 with? How did you construct the form?
From looking at the source it seems like it matches on the form type (e.g.
%Phoenix.HTML.Form{}) and then on the form source (e.g.%Ash.Changeset{}) and delegates to the source’sadd_error.For a changeset, passing a string should be fine:
zachdaniel
Great answer! I think likely the issue with it not displaying is around the error not being attached to a field in the form, and for that to happen, the error has to have a field/path attached to it.
The best way to make that happen is to provide a
field, and optionally apathif the error is in a nested form. i.eindiosmo
Hi Zach, I’m new to both Ash and Elixir so I might be misunderstanding something, but it looks like the @doc and the name of the arguments for
AshPhoenix.Form.add_error/3do not match what you suggested.The second argument being
pathon the general case and the Phoenix.HTML.Form case and beingerrorin the actual implementation looks confusing, especially since the function taking apathargument as I understand it, simply unwraps the underlying Ash.Form from the Phoenix form.source and delegates to the function takingerror.The @doc says
But you provided a keyword list, which as I understand it binds to the
path/errorargument, with opts being empty. Yourpath: [:comments, 0]being one item in your keyword list, but then the function actually looks for path in optsif opts[:path] do.So maybe updating the doc/variable names or adding a @spec would help here.
zachdaniel
Oops! You’re totally right! Technically a path can be specified in the options to the
add_errorfunction, or in the options to create the error itself.The documentation of
Ash.Changeset.add_errorwas updated recently to link toAsh.Error, so that issue is handled, but I will fix theAshPhoenix.Formerror nowzachdaniel
Fixed here: improvement: simplify setting valid on `AshPhoenix.Form.add_error/3` · ash-project/ash_phoenix@b136825 · GitHub