So up until this point my experience with Collection2/Simple Schema has been basic at best. Now, I'm trying to validate values for 'types' based on documents in a Type collection.
@Data = new Mongo.Collection 'data'
Data.attachSchema new SimpleSchema
'types':
'type': [String]
'label': 'Types'
'custom': ->
if @isSet
Meteor.call 'isType', @value, (error, result) ->
if !result
Data.simpleSchema().namedContext('admin_update').addInvalidKeys [
'name': 'types'
'type': 'notAllowed'
]
'otherField':
'type': Number
'label': 'Other Field'
'optional': true
So far, my isType Method has been validating the values correctly, but regardless of whether it returns true or false, it stores the value anyway (even though the form flashes the error message briefly). I don't think I grasp custom validation well enough to figure out how to do this correctly, so any and all help would be appreciated, even if it's just pushing me in the right direction.