Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link to offending fields in case of validation failure #7

Open
bjuretic opened this issue May 1, 2018 · 6 comments
Open

Add link to offending fields in case of validation failure #7

bjuretic opened this issue May 1, 2018 · 6 comments

Comments

@bjuretic
Copy link

bjuretic commented May 1, 2018

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?

@bobfp
Copy link
Owner

bobfp commented May 1, 2018

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

@bjuretic
Copy link
Author

bjuretic commented May 1, 2018

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.

@bobfp
Copy link
Owner

bobfp commented May 2, 2018

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.

@bjuretic
Copy link
Author

bjuretic commented May 7, 2018

Makes sense.

@vheathen
Copy link

vheathen commented Aug 4, 2019

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

@scottming
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants