Closed ggrimbert closed 8 years ago
Another weird thing, validateJs can have options, one of them is 'fullMessages', that permits to not show the name of the field in the error message, but I can't make it work. I believe this is due to
var result = (0, _validate3.default)(target, validator); (validation-rule.js)
but the function called here needs 3 parameters.
Most people's approach at the moment is to call validate, and in the subscribe call back, set the returned errors to a local variable that you can then check. I agree that it should return the errors, and so much so that I put exactly that behaviour in my refactoring test PR, which I unfortunately still need to sort out though. (not great with git/github)
In order to send the options, you can pass the config into either the fluent or decorators parameters.
For example...
new Validator(this).ensure('firstname').required({message:'^Fill it in dummy'});
will replace the default validatejs message with "Fill it in dummy" (note the ^, stops validate js from prepending the property name).
Thanks for the tip with the ^, this works perfectly.
The validate
method doesn't return the results, they are reported via the reporter. The readme shows an example.
Hi,
I am integrating your validators methods inside my app, and I just come to find something weird :
In the method Validate (Validator.js)
You make a call to config.validate, which returns the errors, but you never return the call to this method, so the validate never returns anything.
(validation-config.js)
In my case, I want the validation on "save" button click, and if the result of the validation is OK, then I save.
So, am I supposed to put my save code inside the reporter.subscribe method, or set a variable in this method (in the case this call is synchronous), or am I missing something ?