port5432
port5432

Reputation: 6381

Simple Schema valid values lists

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

Upvotes: 2

Views: 2090

Answers (1)

AAWaheed
AAWaheed

Reputation: 152

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

Upvotes: 6

Related Questions