You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
Custom message in the constraint
Custom message in resource bundle for that specific entity, property, type
Generic resource bundle for that validation type
Custom ColdBox app setting for global message for that validation type
Default message for that validation type
The text was updated successfully, but these errors were encountered:
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:
but what if I wanted the MinValidator to say
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:
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:
So the order of validation message lookups would be like so ({placeHolder} replacements would be supported at all levels):
Custom message in the constraint
Custom message in resource bundle for that specific entity, property, type
Generic resource bundle for that validation type
Custom ColdBox app setting for global message for that validation type
Default message for that validation type
The text was updated successfully, but these errors were encountered: