Hi everyone !
I’m trying to populate an autoform select with another collection.
Annnnnnnd i’m not successful at the moment.
Here is my code :
<template name="insertFormModelesTemplate">
{{#autoForm collection="Modeles" id="insertModelesForm" type="insert"}}
<fieldset>
<legend>Ajouter un modèle</legend>
{{> afQuickField name='nom'}}
{{> afQuickField name='marqueId' options='marqueOptions'}}
</fieldset>
<button type="submit" class="btn btn-primary">Ajouter</button>
{{/autoForm}}
</template>
Template.registerHelper("marqueOptions", function() {
return Marques.find().map(function (marque) {
return {label: marque.name, value: marque._id};
});
});
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
Modeles = new Mongo.Collection('modeles');
Modeles.attachSchema(new SimpleSchema({
nom: {
type: String,
label: "Nom"
},
marqueId: {
type: String,
label: "Marque",
autoform: {
type: "select"
}
}
}, { tracker: Tracker }));
Here is the errors I’m getting in the dev console when the app run :
Exception in template helper: TypeError: Cannot read property 'toString' of undefined
at http://localhost:3000/packages/aldeed_autoform.js?hash=954bc02e0fca04fa83ea45bb5b4206380192fdad:5486:26
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=884c0f04552531e604be5ca6d94381bbf1550f5c:152:22)
at Object.contextAdjust (http://localhost:3000/packages/aldeed_autoform.js?hash=954bc02e0fca04fa83ea45bb5b4206380192fdad:5446:7)
at Object.afFieldInputContext (http://localhost:3000/packages/aldeed_autoform.js?hash=954bc02e0fca04fa83ea45bb5b4206380192fdad:7006:78)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3051:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1715:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3102:27
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:172:18)
Exception in template helper: TypeError: Cannot read property 'class' of undefined
at Object.addClass (http://localhost:3000/packages/aldeed_autoform.js?hash=954bc02e0fca04fa83ea45bb5b4206380192fdad:624:22)
at Object.attsPlusFormControlClass (http://localhost:3000/packages/aldeed_autoform.js?hash=954bc02e0fca04fa83ea45bb5b4206380192fdad:7950:29)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3051:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1715:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3102:27
at Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:172:18)
at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:106:25)
at Object.Spacebars.attrMustache (http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:122:39)
Does someone see my mistake(s) ?