2

I'm using Simple Schema, and I'd like to have a way to validate the values in some fields against a predefined list or against another

Validate against a predefined, not changing list (like an enum). This could probably be done with a complicated regex but this doesn't feel right:

dialogType: {
   type: String,
   label: "Dialog Type",   // 'article', 'sentence','exercise','lesson','word'
   optional: false
},

Validate against the user collection, potentially with some filters applied:

userId: {
    type: String,
    label: "User ID",
    optional: false
 } 

A related question Bind allowedValues to values from a collection in simple-schema

Community
  • 1
  • 1
port5432
  • 5,889
  • 10
  • 60
  • 97

1 Answers1

6

I guess you can do it as follows:

dialogType: {
    type: String,
    allowedValues: ['article', 'sentence','exercise','lesson','word'],
    optional: true
},

Did you look at https://github.com/aldeed/meteor-simple-schema#allowedvalues

AAWaheed
  • 152
  • 1
  • 5