Open segungreat opened 1 year ago
Hey @segungreat 👋
If the rules
method is returning an object, you can use the messages
property: https://docs.adonisjs.com/guides/validator/custom-messages.
However, if the method is returning a Validator class, you'll need to define the messages as a class attribute:
import { schema, CustomMessages } from '@ioc:Adonis/Core/Validator'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class CreateUserValidator {
constructor (protected ctx: HttpContextContract) {
}
public schema = schema.create({
})
public messages: CustomMessages = {}
}
Thank you I fixed the problem
I think you need to put this in the readme file
` public rules() { return { schema: schema.create({
email: schema.string({}, [
rules.trim(),
rules.email(),
rules.disposable(),
rules.normalizeEmail({
allLowercase: true,
gmailRemoveDots: true,
gmailRemoveSubaddress: true,
}),
rules.escape(),
rules.unique({ table: 'users', column: 'email', caseInsensitive: true })
]),
}),
messages: {
required: 'The {{ field }} is required to create a new account',
'username.unique': 'Username not available'
}
}
}`
For ease
Will try to improve the docs for the next version (waiting for Adonis V6 to be released so that I can also improve this package).
Hello, thank you for the package, really awesome
I have been trying to add validation message, can you put me through how to add validation message in custom message and in translations.
Thank you