joi icon indicating copy to clipboard operation
joi copied to clipboard

Custom message for required field

Open carlosleal89 opened this issue 2 years ago • 3 comments

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 avatar Mar 25 '24 15:03 carlosleal89

hey @carlosleal89 , can i work on this issue?

AdarshBajpai67 avatar Apr 10 '24 17:04 AdarshBajpai67

hey @carlosleal89 , can i work on this issue?

Hi. Yes, please :)

carlosleal89 avatar Apr 17 '24 13:04 carlosleal89

It works for me on [email protected]: 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

Nargonath avatar Apr 17 '24 16:04 Nargonath