i have three fields in a Collection:
Cards.attachSchema(new SimpleSchema({
foo: {
type: String,
},
bar: {
type: String,
},
foobar: {
type: String,
optional: true,
autoValue() {
if (this.isInsert && !this.isSet) {
return `${foo}-${bar}`;
}
},
},
);
So i want to have the field foobar to get as auto(or default) value, if not explicitly set, to return both values of foo and bar. Is this possible?
You may use the
this.field()method inside yourautoValuefunction:Related reading: https://github.com/aldeed/simple-schema-js#autovalue
However, you could also solve this by using a hook on the
insertmethod of your collection. There you could assume the valuesfooandbarto be present, because your schema requires them: