sifat
April 26, 2017, 1:56pm
1
Hi all,
This will sound simple but I can’t get the select options into my drop down form from AutoForm. Here’s my collection and schema:
export const Matchings = new Mongo.Collection('matchings');
Matchings.attachSchema(new SimpleSchema({
title: {
type: String,
label: "Title",
max: 200
autoform: {
type: 'select',
options: function() {
return [{ label: "2013", value: 2013 }, { label: "2014", value: 2014 }, { label: "2015", value: 2015 }] }
}
},
....
And template:
<template name="matchingstemplate">
{{#autoForm collection=Collections.Matchings id="insertBookForm" type="insert"}}
<fieldset>
<legend>Add a Book</legend>
{{> afQuickField name='title'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}
</template>
The title does not show the list of options like 2014, 2015, etc. Is there something simple I’m missing? AutoForm works fine for me otherwise.
mattl
April 27, 2017, 1:01am
2
If you’re using AutoForm 6.0 then you’ll need to extend SimpleSchema to support the autoform
option by calling:
SimpleSchema.extendOptions(['autoform']);
See https://github.com/aldeed/meteor-autoform/#installation
sifat
April 27, 2017, 7:56am
3
Hi, I just installed that and put in the 2 lines of code, but getting this app error:
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
Errors prevented startup:
While building for web.browser:
imports/api/getmatchings.js:15:8: Unexpected token (15:8)
While building for os.windows.x86_32:
imports/api/getmatchings.js:15:8: Unexpected token (15:8)
Your application has errors. Waiting for file change.
sifat
April 27, 2017, 8:51am
4
Actually it looks like I have autoform version 5.8.1. I’m having issues with installing simple schema because of a bcrypt issue (I’m on Windows). Is there an alternate way to have select options without simple schema?
mattl
April 27, 2017, 9:37pm
5
I see. In that case the easiest thing to do is to use a helper that returns the options. See https://github.com/aldeed/meteor-autoform/#use-a-helper .
ralof
April 28, 2017, 12:07am
6
try skipping: type: ‘select’
I just use
mySelect: {
label: "Ehuru",
type: String,
autoform: {
options: [
{label: "Home", value: "yes"},
{label: "Away", value: "maybe"},
{label: "Paris", value: "Sleeping"} ]
}
},