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

Returning error messages just once for every field #2287

Closed
iedmrc opened this issue Jan 30, 2020 · 1 comment
Closed

Returning error messages just once for every field #2287

iedmrc opened this issue Jan 30, 2020 · 1 comment
Assignees
Labels
support Questions, discussions, and general support

Comments

@iedmrc
Copy link

iedmrc commented Jan 30, 2020

Support plan

  • which support plan is this issue covered by?
    Community
  • is this issue currently blocking your project?
    Partially
  • is this issue affecting a production system?
    No

Context

  • node version:
    v10.8.0
  • module version:
    17.1.0
  • environment (e.g. node, browser, native):
    node.js
  • used with (e.g. hapi application, another framework, standalone, ...):
    another framework (strapi)
  • any other relevant information:

How can we help?

Hi,
As in the title, I want to return just one error message for every field.
I tried error() and it just returns the very first error even {abortEarly: false} is set.
I tried message(), messages(), rule() with ruleset and either they did nothing or I got "Error: Cannot set flag inside a ruleset". I just want to do a very simple thing but couldn't for 3-4 hours. I read documents and issues and tried all I understand, as listed above. Some were legacy (belongs to older versions) some were not worked.
How can I achieve this?
Thanks!

@iedmrc iedmrc added the support Questions, discussions, and general support label Jan 30, 2020
@hueniverse
Copy link
Contributor

You either get one error for the entire validation process or you get every single error found. If you are using error() it will override all other errors because it is designed to return custom errors and not joi validation errors. You will need to write your own error processor that consolidates the errors per field. Not sure how that will work if you have sub field, but this is not a common use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

2 participants