const messages = {
'required': '{{ field }} is required to create a new account'
}
The messages layer of indicative also let you define placeholders for runtime values. This is useful, when you want to have generic messages for certain validations.
const messages = {
'required': '{{ field }} is required to create a new account'
}
The field
will be replaced with the current field under validation. However, you can define specific messages for certain fields in combination with generic messages.
const messages = {
'required': '{{ field }} is required to create a new account',
'username.required': 'Please choose a unique username for your account'
}
Now every field under validation will use the required
message apart from the username
field, since we defined a specific message for it.
Key | Description |
---|---|
field |
The name of the current field under validation. For nested arrays, it will be |
validation |
The name of the current validation. |
argument |
An array of
|
Also you can bind a closure
as a custom message and return value will be used as the message string. This is useful, when you want to compute some values as runtime.
const messages = {
range: function (field, validation, args) {
return `The ${field} must be over ${args[0]} and under ${args[1]} years`
}
}