hapijs / hapijs/joi

Custom message for required field

Open
#3,024 3 comments 0 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

### 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.

```js
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.