Validation via simpleSchema for String OR Boolean


#1

I send form values to a method and I’m using this SimpleSchema for validation.

new SimpleSchema({
	id   : { type: String, regEx: SimpleSchema.RegEx.Id },
	key  : { type: String },
	value: { type: String }
})

So this works great for input or textarea values. But there are also checkboxes, which gives Boolean value (.is(:checked)).
But I didn’t find any solution how to check for String OR Boolean value. How can I do that?

Something like

value: { type: String|Boolen }

#2

#3

What am I doing wrong?

new ValidatedMethod({
    validate: new SimpleSchema({
	id   : { type: String, regEx: SimpleSchema.RegEx.Id },
	key  : { type: String },
	value: { Match.Optional(Match.OneOf(String, Boolean)) }
    }).validator(),
    // ...
});