arcanemachine

arcanemachine

How to add a global error to an Ecto changeset? (Not specific to a single field)

In Django, there is the concept of “non_field_errors”, which exists when a form field has an error that is not specific to any model field.

I am just wondering if there is a similar convention in Ecto. I have an error that is not specific to a single field. How should I describe it? Should I just use the django naming convention for the field, e.g. :non_field_errors? For example:

Ecto.Changeset.add_error(changeset, :non_field_errors, "some reason")

Just checking for recommendations. Thanks

Marked As Solved

sodapopcan

sodapopcan

You can add those to :base.

Also Liked

arcanemachine

arcanemachine

Interesting, that’s also what ChatGPT suggested. Is there any precedent for this specific value?

EDIT: The venerable Dogbert suggested the value :base in a Stack Overflow answer

sodapopcan

sodapopcan

I’m assuming the precedent is Rails! It also uses :base.

arcanemachine

arcanemachine

Cool, works for me. I just want to have some sort of convention to work with. The fewer decisions I have to make, the better.

Thanks Brother sodapopcan!

Last Post!

arcanemachine

arcanemachine

Cool, works for me. I just want to have some sort of convention to work with. The fewer decisions I have to make, the better.

Thanks Brother sodapopcan!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement