As far as I can tell from the documentation, the most flexibility allowed in a custom error template is to provide a static template string with placeholders, like:
But it seems like it should be possible to allow for a function to be assigned there as well. That way I can do more complex transformations on the attrib and rule name.
Use Cases:
I want to apply i18n to my validation and even though the identifier on my HTML form is "email", I want to show an error message with the string "courrier électronique" to french visitors, not "email".
The attrib identifier string must be one word for programmatic reasons, like "mobile_phone_number" and I want to display an error message like "Your mobile phone number is not valid."
I want to tweak the display of the attrib identifier in some other way, like ucfirst, in a template like ":attrib: is required."
It seems like you could update the API to accept either a static string template or an anonymous function, so that the following would work.
'errorTemplate' => function ($attrib, $rule) {
// make whatever transforms on the $attrib and $rule arguments you want
return "Attribute $attrib violated rule $rule."
}
As far as I can tell from the documentation, the most flexibility allowed in a custom error template is to provide a static template string with placeholders, like:
But it seems like it should be possible to allow for a function to be assigned there as well. That way I can do more complex transformations on the attrib and rule name.
Use Cases:
ucfirst
, in a template like ":attrib: is required."It seems like you could update the API to accept either a static string template or an anonymous function, so that the following would work.