mongodbmeteormeteor-autoformsimple-schema

Meteor multiple-select autoform


I'm new to meteor and I have problems with the meteor autoform from aldeed/meteor-autoform

I'd like to implement a Multiple-selection box.

Exercises = new Mongo.Collection('exercises');
ExerciseSchema = new SimpleSchema({
name: {
    label: "Name",
    type: String
},
tags: {
    label: "Tags",
    type: Tags
}});

Tags = new SimpleSchema({
wow: {
    type: String,
    allowedValues: ['red', 'green', 'blue'],
    autoform: {
        options: [
            {label: "Red", value: "red"},
            {label: "Green", value: "green"},
            {label: "Blue", value: "blue"}
        ]
    }
}});

And in my html I insert

{{#autoForm collection="Exercises" id="insertExerciseForm" type="insert" resetOnSuccess=true}}
            <div class="card-content">
                {{> afQuickField name='tags.wow' type='select-multiple'}}
            </div>

In the Browser it looks correct like Multiple select box select

But when I select multiple elements and click the submit button from my Autoform, I get this error in my Browser Console:

Error in insertExerciseForm insert Error: Wow must be of type String

When I remove the type='select-multiple' from the afQuickField then I can select only one element and it works fine. But I need to select mutiple elements

Can someone help me?


Solution

  • [String] does not help.

    I found it out.

    Tags = new SimpleSchema({
    wow: {
    type: Array,
    allowedValues: ['red', 'green', 'blue'],
    autoform: {
        options: [
            {label: "Red", value: "red"},
            {label: "Green", value: "green"},
            {label: "Blue", value: "blue"}
        ]
    },'wow.$': {
        type: String
    },
    }});
    

    but now, it just saves the value in MongoDB, how can I save label and value?