guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

Question: Can we use the message en value from an object instead of a literal string #1350

Closed manjindersarkaria closed 3 years ago

manjindersarkaria commented 3 years ago

HI I am having an issue with the custom validator. In my env i have to add the custom validator and each custom validator have there own custom message, I implemented the way documentation said that is like this window.Parsley.addValidator('formulaSyntax', { validateString: function(value) { return parser.checkSyntax(value); }, messages: { en: 'Formula Syntax is wrong' } })

this whole thing works fine, but now I want to provide that message using some object or want to return the en part using a function like

window.Parsley.addValidator('formulaSyntax', { validateString: function(value) { return parser.checkSyntax(value); }, messages: { en: i18next.t('feedback.wrongSyntax') } }) This does not work. Is there a way I can provide the value using an object or funcion?

marcandre commented 3 years ago

https://stackoverflow.com/questions/44304642/parsley-js-dynamic-messages-in-custom-validator