skooma icon indicating copy to clipboard operation
skooma copied to clipboard

Add link to offending fields in case of validation failure

Open bjuretic opened this issue 7 years ago • 6 comments

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?

bjuretic avatar May 01 '18 08:05 bjuretic

This makes sense. Do you have an example of what the structured error output should look like?

bobfp avatar May 01 '18 10:05 bobfp

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.

bjuretic avatar May 01 '18 18:05 bjuretic

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.

bobfp avatar May 02 '18 20:05 bobfp

Makes sense.

bjuretic avatar May 07 '18 08:05 bjuretic

Would also love to have field name in errors array. And possibly hide field values in error messages.

vheathen avatar Aug 04 '19 08:08 vheathen

Any updates?

scottming avatar Nov 08 '20 01:11 scottming