-
-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Allow all the built-in validation messages stored in /coldbox/system/validation/validators to be overridden on a global level.
For instance, the MinValidator has a default error message of:
message="The '#arguments.field#' value is not greater than #arguments.validationData#"
but what if I wanted the MinValidator to say
"I'm sorry, but you need to enter a {field} value that is not smaller than {validationData}"
everywhere in the site without specifying a custom message in every entity?
Abstract all the default messages out of the validators and store them in the default config using the {placeHolder} method for everything. Let users override the default messages for each validator in the ColdBox config. This will allow for system-wide validation message overrides per type in one place. Something like:
validation = {
defaultMessages = {
required = "The '{field}' value is required",
type = "The '{field}' has an invalid type, expected type is {validationData}",
size = "The '{field}' values is not in the required size range ({validationData})",
range = "The '{field}' value is not the value field range ({validationData})"
}
}
Additionally, create some new conventions to overriding default validator messages by constraint type with resource bundles. For instance, this would allow you to specify the default Spanish message for a required field once in your resource bundle for the entire site. I'm thinking something like this in your resource bundle:
cb_defaultValidationMessage.required = The 'field}' value is required
cb_defaultValidationMessage.type = The '{field}' has an invalid type, expected type is {validationData}
cb_defaultValidationMessage.size = The '{field}' values is not in the required size range ({validationData})
cb_defaultValidationMessage.range = The '{field}' value is not the value field range ({validationData})
So the order of validation message lookups would be like so ({placeHolder} replacements would be supported at all levels):