Exception in template helper: TypeError: Cannot read property 'singleType' of undefined

284 views Asked by At

I am using Meteor 1.6 and trying to update a collection using aldeed's quickForm below is my code.

COLLECTION:

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);

export const Settings = new Mongo.Collection('Settings');

SettingsSchema = new SimpleSchema({
    "userId": {
        type: String,
        label: "User ID",
    },
    "speed": {
        type: Number,
        label: "Speed",
    },
    "fuelLevel": {
        type: Number,
        label: "Fuel Level",
    },
    "fuelCapacity": {
        type: Number,
        label: "Fuel Capacity",
    },
    "temperature": {
        type: Number,
        label: "Temperature",
    },
}, { tracker: Tracker });

Settings.attachSchema(SettingsSchema);

UI.js

import './ManageAlerts.html';
import '../../../components/common/staggering/Staggering';
import { Settings } from '/imports/api/users/settings';

window.Settings = Settings;

Template.ManageAlerts.onCreated(function () {
    console.log('Landed on page');
    this.subscribe('Settings.Individual');
});

Template.ManageAlerts.helpers({
    settings() {
        return Settings.find({ userId: Meteor.userId() });
    },
    Settings() {
        return Settings;
    }
});

UI.html

<template name="ManageAlerts">
    <div class="content">
        <div class="row">
            {{#each settings}} {{> quickForm collection="Settings" id=_id type="update" doc=this}} {{/each}}
        </div> 
    </div>
</template>

ERROR:

Exception in template helper: TypeError: Cannot read property 'singleType' of undefined
    at SimpleSchema.getQuickTypeForKey (http://localhost:3000/packages/modules.js?hash=205c3cd7764df56011db912e818af184cf564869:30655:40)
    at Object.getInputType (http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:2469:29)
    at Object.afFieldInputContext (http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:6383:30)
    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)
    at http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:6317:23

Any help would be deeply appreciated.

1

There are 1 answers

0
Jankapunkt On

This error occurs when your collection is undefined.

One possible fix could be to make the collection global like so:

global.Settings = Settings; // try this instead of window

Otherwise you can just change the way the template returns the collection to the form:

{{> quickForm collection=Settings id=_id type="update" doc=this}}

Now it uses a helper to explicitly receive the collection instead of looking at the global scope, because you have already defined this helper:

Settings() {
    return Settings;
}

If this still does not work please also check if the collection is correctly imported by the given path (for example try not starting with /imports but relative this the current dir).