skooma
skooma copied to clipboard
Add link to offending fields in case of validation failure
Hi,
the lib is good, but the error output it produces are strings, and not some structure like in Ecto's Changeset, from which the errors for the offending fields can be extracted.
So the issue is the use of your library forces you to have external API (as an example of use) where all the validation messages are just strings, without a key (field name), so they are difficult to use by the client of such an API.
Maybe you could add another valid? function that would return more details about the field which caused the error, so that it can be better formatted by the user of the library?
This makes sense. Do you have an example of what the structured error output should look like?
Hi, thanks for a quick reply.
Well I suggest something simple, like:
errors: %{
first_name: ["cannot be empty"], # one message
age: ["must be over 18", "must be below 25"], # two validators failed for this field
# example of a nested structure:
person: [
title: ["cannot be empty"]
]
}
So nothing crazy, just a way to get messages out based on field keys.
You caught me at a good time. I'll put something together over the next few days. I'm thinking about making your solution more of the default, and then providing a helper function that turns the error object into a human readable version.
Makes sense.
Would also love to have field name in errors array. And possibly hide field values in error messages.
Any updates?