hapijs / hapijs/joi

How can I set a custom message for my error regarding ref?

Open
#2,840 0 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

#### Support plan

* *is this issue currently blocking your project?* (yes/no): yes
* *is this issue affecting a production system?* (yes/no): yes

#### Context

* *node version*: ^17.5.0
* *module version*: ^17.5.0
* *environment* (e.g. node, browser, native): browser
* *used with* (e.g. hapi application, another framework, standalone, ...): react
* *any other relevant information*:

#### How can we help?
I am using Joi validation to validate my input fields, where price and maxPrice are relevant fields. When setting a value for maxPrice and not price I get the error message: "maxPrice" limit references "ref:price" which must be a number. How can I define this error message?

```js
maxPrice: Joi.number().unsafe().positive().allow(null).greater(Joi.ref('price')).messages({
'number.base': 'message',
'number.positive': 'message',
'number.greater': 'message'
})
```

This is my current code for maxPrice.

```js
const some = 'properly formatted code example';
```

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.