Closed Bandit closed 6 years ago
Hey Bandit, Can you show us your simpl-schema ?
Here's an example schema showing my current approach to this problem
Items.schema = new SimpleSchema({
_id: {
type: String,
label: 'The ID of this item',
optional: true,
custom() {
// only required on an update
if (!this.isSet && this.operator === '$set') return 'required';
},
},
createdAt: {
type: String,
label: 'The date this item was created',
optional: true,
autoValue() {
if (this.isInsert) return (new Date()).toISOString();
},
},
updatedAt: {
type: String,
label: 'The date this item was last updated',
optional: true,
autoValue() {
if (this.isInsert || this.isUpdate) return (new Date()).toISOString();
},
},
[...]
});
try running ss.clean
frist then ss.validate
.
Items.schema.clean(item);
Items.schema.validate(item);
Every time I
validate()
, it throws an error because the AutoValue key doesn't exist (because the client doesn't run AutoValue functions I'm guessing). Is the correct way to deal with this to add anoptional: true
flag?Relevant closed issue: https://github.com/aldeed/meteor-autoform/issues/1218