meteor-collection2
meteor-collection2 copied to clipboard
[object Object] Issue with Simple Schema and quickForm
I am not sure why I am getting this error when ever I load in my modal with my quickForm. It just keeps on showing [object Object]. Im assuming that I passed an object and it cant represent it with the label. How can I fix the issue.
HTML users.html
<template name="users">
<div class="row">
<div class="col s12" align="right">
<a class="waves-effect waves-light btn modal-trigger" href="#modal1">Add a User</a>
</div>
{{#each users}}
{{>user}}
{{/each}}
</div>
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-content">
<h4>Add new User</h4>
{{> quickForm collection="Users" id="insertUserForm" type="insert" class="new-user-form"}}
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat">
Close
</a>
</div>
</div>
</template>
JavaScript users.js
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
export const Users = new Mongo.Collection('users');
const UserSchema = new SimpleSchema({
firstName: {
type: String,
label: "First Name",
},
lastName: {
type: String,
label: "Last Name",
},
email: {
type: String,
label: "E-Mail",
},
createdAt: {
type: Date,
autoform: {
type: 'hidden',
label: false,
},
defaultValue: new Date(),
},
});
Users.attachSchema( UserSchema );
JavaScript body.js
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Users } from '../api/users';
import './body.html';
import './users.html';
window.Users= Users;
Template.body.onCreated(function bodyOnCreated(){
Meteor.subscribe('users.allusers');
});
Template.registerHelper('formatDate', function(date){
return moment(date).format('ll');
});
Template.users.helpers({
users(){
return Users.find({});
},
});
Template.users.onRendered(function(){
$('#modal1').modal();
});
Reproduced on: Meteor v1.8.1 simple-schema v1.5.3 collection2 v3.0.1 autoform v6.3.0
Here is a github repository with a fresh minimalistic meteor project reproducing the bug:
Steps:
- $ meteor create --full test
- $ cd test
- $ meteor npm install simpl-schema
- $ meteor add aldeed:collection2
- $ meteor add aldeed:autoform
- add file
./imports/startup/both/myCollection.js
with content:
import { Mongo } from 'meteor/mongo'
import SimpleSchema from 'simpl-schema'
import { Tracker } from 'meteor/tracker'
SimpleSchema.extendOptions(['autoform'])
const myCollectionSchema = new SimpleSchema({
myField: String
}, {tracker: Tracker})
MyCollection = new Mongo.Collection('myCollection')
MyCollection.attachSchema(myCollectionSchema)
- replace the content of
./imports/ui/pages/home/home.js
with
<template name="App_home">
{{> quickForm collection="MyCollection" id="insertMyCollectionForm"
type="insert"}}
</template>
- $ meteor
- open browser and load address
localhost:3000
9.1) Expected to see a form contain a text field 9.2) Actual result:
This is the browser log:
Exception in template helper: TypeError: Cannot convert undefined or null to object
at Function.from (<anonymous>)
at _toConsumableArray (http://localhost:3000/packages/modules.js?hash=b9e3205bd02466aafd035f03d78dd1a11c4d3ea8:1144:182)
at SimpleSchema.getAllowedValuesForKey (http://localhost:3000/packages/modules.js?hash=b9e3205bd02466aafd035f03d78dd1a11c4d3ea8:1741:24)
at Object.autoFormGetOptionsForField [as _getOptionsForField] (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:2559:22)
at Object.afQuickFieldsQuickFieldAtts (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:6721:31)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3051:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1715:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769:14)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3102:27
meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:1048 Exception in template helper: TypeError: Cannot read property 'singleType' of undefined
at SimpleSchema.getQuickTypeForKey (http://localhost:3000/packages/modules.js?hash=b9e3205bd02466aafd035f03d78dd1a11c4d3ea8:1400:40)
at Object.getInputType (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:2469:29)
at Object.bsFormGroupSkipLabel (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:7576:25)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3051:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1715:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769:14)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3102:27
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:172:18)
at Template.afFormGroup_bootstrap3.HTML.DIV.HTML.SPAN.class (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:7533:22)
meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:1048 Exception in template helper: TypeError: Cannot read property 'singleType' of undefined
at SimpleSchema.getQuickTypeForKey (http://localhost:3000/packages/modules.js?hash=b9e3205bd02466aafd035f03d78dd1a11c4d3ea8:1400:40)
at Object.getInputType (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:2469:29)
at Object.getTemplateName (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:6343:30)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3051:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1715:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769:14)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3102:27
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:172:18)
at http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:6316:27
meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:1048 Exception in template helper: TypeError: Cannot read property 'singleType' of undefined
at SimpleSchema.getQuickTypeForKey (http://localhost:3000/packages/modules.js?hash=b9e3205bd02466aafd035f03d78dd1a11c4d3ea8:1400:40)
at Object.getInputType (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:2469:29)
at Object.afFieldInputContext (http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:6383:30)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3051:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:1715:16
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3769:14)
at http://localhost:3000/packages/blaze.js?hash=51f4a3bdae106610ee48d8eff291f3628713d847:3102:27
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:172:18)
at http://localhost:3000/packages/aldeed_autoform.js?hash=8256b47860e9ff64198d4ed1a74cae7b91e183de:6317:23
I have been able to reproduce this without using Collection2, thus I conclude this is an AutoForm related error. Found this issue https://github.com/aldeed/simple-schema-js/pull/291 there are 2 possible pull requests waiting for merge. Downgrading Simpl-Schema to 1.4.3 is the current workaround.
This ticket is not Collection2 related and can be closed.