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

Custom message for required field #3024

Open
carlosleal89 opened this issue Mar 25, 2024 · 3 comments
Open

Custom message for required field #3024

carlosleal89 opened this issue Mar 25, 2024 · 3 comments
Labels
support Questions, discussions, and general support

Comments

@carlosleal89
Copy link

Runtime

node

Runtime version

18.19.0

Module version

17.12.2

Used with

React TS

Any other relevant information

No response

How can we help?

Hello!
I'm trying to set a custom error message for a required field, but always show the default message. For example:
message ""password" is not allowed to be empty"

Bellow you can see the schema.

export const loginValidator = Joi.object({
  email: Joi.string()
    .email({ tlds: { allow: false } })
    .message('"Email" inválido.')
    .required(),
  password: Joi.string()
    .min(6)
    .required()
    .messages({
      'string.min': 'Password deve conter pelo menos 4 caracteres',
      'any.required': 'Informe o password'
    })
})

The custom message set to 'string.min' is working as expected, but 'any.required' not.

@carlosleal89 carlosleal89 added the support Questions, discussions, and general support label Mar 25, 2024
@AdarshBajpai67
Copy link

hey @carlosleal89 , can i work on this issue?

@carlosleal89
Copy link
Author

hey @carlosleal89 , can i work on this issue?

Hi. Yes, please :)

@Nargonath
Copy link
Member

It works for me on Joi@17.11.0: https://runkit.com/nargonath/joi-messages-for-any-required

Running it on the website as well which uses 17.12.3 works so the problem might be somewhere else.

image

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

3 participants