1
I’m using the plugin Parsley for form validation and I am creating some additional validation methods, however, I am having difficulty with the customization of the error messages of these functions.
According to the site documentation, we can add a custom method as follows:
window.Parsley.addValidator('equals', {
validateString: function validateString(value, comparar_com, texto_erro) {
return (value === comparar_com);
},
requirementType: 'string',
messages: {
pt_BR: 'O seguinte valor é esperado: %s'
}
});
With the above code Parsley would display in the error message the second parameter of the function, which would be 'compare with', but I wanted the text defined in the third parameter, 'text_error', to be displayed in the error message, and not 'compare with''.
Can anyone tell me if this is possible? Parsley uses the following function to mount the error messages:
// Kind of light `sprintf()` implementation
formatMessage: function formatMessage(string, parameters) {
...
I’m trying something here, still unsuccessful, but am I on the right track?
Yesterday looking at some links on the internet I realized the following, the function validaeString (or any other variation) receives up to three parameters:
value, requirement e fieldInstance
. I mean, the way I was imagining... =(– Paulo de Tarso