Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

Populating select with other collection #1661

Closed erisevaline closed 6 years ago

erisevaline commented 6 years ago

Hi everyone !

I've got almost the same issue as this one Still get errors when using the solving response of the above link.

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 }));
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) ?