Skip to content

Commit

Permalink
docs: document validation options in custom message
Browse files Browse the repository at this point in the history
  • Loading branch information
ndianabasi committed Jun 26, 2024
1 parent cce5ecc commit a070105
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,20 @@ The following validation rules are available:

#### Example usage

Each rule expects a single `number` parameter to be provided.
Each rule expects a single `number` parameter to be provided. Each parameter is injected into the custom validation message via their respect rule names. See the custom message bag in the validation schema below.

```typescript
await ctx.request.validate({
schema: schema.create({
avatar: schema.file(undefined, [rules.maxImageHeight(520)])
avatar: schema.file(undefined, [
rules.maxImageWidth(1000),
rules.maxImageHeight(520),
])
}),
messages: {
'avatar.maxImageHeight': 'Maximum image height is {{ options.maxImageHeight }}',
'avatar.maxImageWidth': 'Maximum image width is {{ options.maxImageWidth }}',
}
})
```

Expand Down

0 comments on commit a070105

Please sign in to comment.