Meteor-Community-Packages / meteor-simple-schema

Meteor integration package for simpl-schema
https://github.com/Meteor-Community-Packages/meteor-simple-schema
MIT License
919 stars 161 forks source link

validateOne is not a function #706

Closed SevenZark closed 7 years ago

SevenZark commented 7 years ago

I've run into a problem with validateOne. In the below code I'm iterating over an object sent to a function, wanting to validate just on the values submitted for change on update, rather than requiring an entire record to be sent to the function (this is to avoid dealing with things like the encrypted password function in meteor user docs, which I deal with in a separate function).

The code, however, yields this error: 'validationContext.validateOne is not a function.' This seems like a pretty straightforward attempt to use that function. I've also tried this using a named validation context, but I still get the same error. Also, if I remove the underscore looping and just try to call validateOne with a key named as a literal, I get the same error.

I know we could get into a big debate about whether it's proper to always send the entire document for update, but I have my reasons for doing it this way, and above all, right now I'm just trying to report what might be a bug. Or maybe the README is out of date and validateOne isn't available anymore?

const cleanUserData = UsersSchema.clean(data),
        validationContext = UsersSchema.newContext()

 _.each(data, function(value, key) {
        validationContext.validateOne(data, key)
})
SevenZark commented 7 years ago

Nevermind, stupid mistake. I'm using the NPM package, which handles this in a different way and does not have that function. I was looking at the wrong docs.