I'm creating a mongoose schema and want to minimize the code. I want size to be required for the fields shown. But when I test it I don't get an error if size isn't included. I tried:
(('flag-silk' || 'costume') || 'accessories-shoes'),
['flag-silk' || 'costume' || 'accessories-shoes'], and ==. Am I missing something or is my syntax wrong?
code:
size: {
type: String,
required: [
function() {
return this.category === ('flag-silk' || 'costume' || 'accessories-shoes');
},
'Please enter the size of the product.'
]
},
That's not the right syntax for the boolean expression you need. Instead, use:
type: String,
required: [
function() {
return ['flag-silk', 'costume', 'accessories-shoes'].indexOf(this.category) !== -1;
},
'Please enter the size of the product.'
]
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With