Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for generic validation message defaults to be configured #15

Open
lmajano opened this issue Mar 8, 2016 · 0 comments
Open

Allow for generic validation message defaults to be configured #15

lmajano opened this issue Mar 8, 2016 · 0 comments

Comments

@lmajano
Copy link
Contributor

lmajano commented Mar 8, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant