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

Setting errors.label to false does not remove labels from error messages for keys with labels #3033

Closed
ZachHaber opened this issue May 1, 2024 · 1 comment · Fixed by #3034
Assignees
Labels
bug Bug or defect
Milestone

Comments

@ZachHaber
Copy link

Runtime

node.js, browser

Runtime version

v18.17.0, chrome 122

Module version

17.13.0

Last module version without issue

No response

Used with

Hapi, and standalone

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

I'm using Joi validation within a form, in which I'd like to not show the name of the field in the error messages as the errors will be displayed underneath the fields, so they don't need the additional context. I'm also using the same schema for validation within my Hapi backend, which I'd like to have the labels for.

The issue is that if you specify a label for a key, then the error messages don't respect the errors.label=false option, but keys without a label do respect it. If this is working as designed, then the docs should be adjusted for clarity:

false - remove any label prefix from error message, including the "".

Reduced example (from the schema tester):

Schema:

Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  birth_year: Joi.number().integer().min(1900).max(2013).label('Birth Year'),
}).options({abortEarly:false, errors: {label: false}})

Data:

{ birth_year: 2014 }

What was the result you got?

{
  "birth_year" /* "Birth Year" must be less than or equal to 2013 */: 2014,
  "username": undefined /* is required */
}

What result did you expect?

{
  "birth_year" /* must be less than or equal to 2013 */: 2014,
  "username": undefined /* is required */
}
@ZachHaber ZachHaber added the bug Bug or defect label May 1, 2024
Marsup added a commit that referenced this issue May 2, 2024
@Marsup Marsup added this to the 17.13.1 milestone May 2, 2024
@Marsup Marsup self-assigned this May 2, 2024
@Marsup Marsup linked a pull request May 2, 2024 that will close this issue
@Marsup
Copy link
Collaborator

Marsup commented May 2, 2024

Thanks for the report, it has been fixed in 17.13.1.

@Marsup Marsup closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants