The Custom validation is not returning the defined error message #4034
Unanswered
FinotiLucas
asked this question in
Help
Replies: 3 comments
-
Hey 👋 Can you show us |
Beta Was this translation helpful? Give feedback.
0 replies
-
Of course, thanks for the reply. @WeyIin import { schema, rules, CustomMessages } from '@ioc:Adonis/Core/Validator'
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class AuthValidator {
constructor(protected ctx: HttpContextContract) {}
public schema = schema.create({
email: schema.string({}, [
rules.email(),
rules.unique({ table: 'users', column: 'email' }),
rules.required(),
rules.minLength(8),
rules.maxLength(255),
]),
nickname: schema.string({}, [rules.required(), rules.minLength(4), rules.maxLength(64)]),
password: schema.string({}, [
rules.required(),
rules.password(),
rules.confirmed(),
rules.minLength(8),
rules.maxLength(255),
]),
})
public messages: CustomMessages = {
'email.unique': 'Incomplete authentication, choose another email address',
'required': 'The {{ field }} is required to create a new account',
'minLength': '{{ field }} must be at least {{ options.minLength }} characters long',
'maxLength': '{{ field }} must be less then {{ options.maxLength }} characters long',
'password_confirmation.confirmed': 'The password and the confirmation password must be equals',
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also have this problem 😢 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Node: v18.4.0
guys, how are you?
I have a doubt, maybe it's very easy to solve but I couldn't.
I am creating a custom password validation rule for my application and even when I add the error message to the "report" the message is not displayed, instead it outputs a default message "password validation failed on password".
and an example of my controller
As you can see in the image below
Should show the following messages
"The password must contain at least 1 uppercase alphabetical character" and "The password must contain at least one special character"
If I try to access the custom messages parameters through the validator method i get an undefined value
Beta Was this translation helpful? Give feedback.
All reactions