Closed ghost closed 9 years ago
Hi, the problem was already discussed here and was solved. The ability to validate a list of fields will appear in the next release. But for now you can use this workaround:
var validateMany = function(doc, fields) {
return _.every(fields, function(field) {
return doc.validate(field);
});
};
// Usage
var user = new User();
if (validateMany(user, ['name', 'date'])) {
// Do something
}
Notice, that it uses the _.every
function instead of _.each
because we want to stop on the first error.
I will probably publish the next version in the next month. I have to make sure that everything works correctly. It was a huge release. I'm finishing creating unit tests. I'm also working on the documentation. I don't want to hurry.
Oh ok, i've really missed the already closed issue on this. Sorry about that. I actually want not to stop on first error, so will it be possible with the new version your building ?
And definitely, take your time, you're building an awesome tool (already awesome actually) !
In the new version you have several ways of calling the validate
function:
validate()
- validates all fields and STOPS after the first errorvalidate(false)
- validates all fields and does NOT STOP after the first errorvalidate('fieldName')
- validates a single fieldvalidate(['first', 'second'])
- validates a list of fields and STOPS after the first errorvalidate(['first', 'second'], false)
- validates a list of fields and does NOT STOP after the first errorSo yes it will be possible :). Thanks for good words :)
Ok, awesome ;)
Thanks a lot for your work again.
Hey jagi,
Validators provide a way to validate a single field or all of them, but i doesn't look like it's possible to do a list validation. For example, like this :
Right now, i'm using it like this :
From what i've read from your code, doesn't look like it's possible right now, but maybe i've missed something ?