-
How can I display errors returned by Ecto changesets in my app? For example, when a unique constraint error occurs (e.g., attempting to create an entry with a duplicate name), it should trigger an error message. Currently, my application gets stuck on the creation screen without displaying any error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You have to add the error under the name of a field you are displaying. For example, if you have a username: %{
module: Backpex.Fields.Text,
label: "Username"
}, you need to add the error under the
|
Beta Was this translation helpful? Give feedback.
You have to add the error under the name of a field you are displaying.
For example, if you have a
username
field like thisyou need to add the error under the
username
key to the changeset.Ecto.Changeset.unique_constraint/3
also has anerror_key
option, which in this case should be:username
.@sneha-saj