Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running the project - Leading decorators must be attached to a class declaration! #376

Open
BehrouzRiahu opened this issue Nov 28, 2016 · 2 comments

Comments

@BehrouzRiahu
Copy link

BehrouzRiahu commented Nov 28, 2016

When I try and add the Posts collection as it is shown int he package example as follows:

@Schemas = {}

@Posts = new Meteor.Collection('posts');

Schemas.Posts = new SimpleSchema
	title:
		type: String
		max: 60
	content:
		type: String
		autoform:
			rows: 5
	createdAt:
		type: Date
		label: 'Date'
		autoValue: ->
			if this.isInsert
				return new Date()
	owner:
		type: String
		regEx: SimpleSchema.RegEx.Id
		autoValue: ->
			if this.isInsert
				return Meteor.userId()
		autoform:
			options: ->
				_.map Meteor.users.find().fetch(), (user)->
					label: user.emails[0].address
					value: user._id

Posts.attachSchema(Schemas.Posts)

I get back the following error: "Leading decorators must be attached to a class declaration"

What am I doing wrong here?

And is it possible to play around with the design the content of the /admin content? because I couldn't figure out how, I would appreciate it if someone could confirm it for me before I start using it :)

@tsrandrei
Copy link

take a look at this :
https://github.com/aldeed/meteor-autoform

I think need some reformatting. I am trying to figure out how it works everything.

Did you find any solution?

@tsrandrei
Copy link

tsrandrei commented Jan 6, 2017

They have written all the documentation in CoffeeScript, so basically you should translate it in JavaScript if you are not running CoffeeScript.

By far this is in JS :

collections/posts.js ( or collection common.js file )


var Schemas = {};

Posts = new Meteor.Collection('posts');

Schemas.Posts = new SimpleSchema({
    title:{
        type: String,
        max: 60
    },
    content:{
        type: String,
        min: 20,
        max: 1000,
        autoform: {
            rows: 5
        }
    },
    createdAt:{
        type: Date,
        label: "Date",
        autoform:{
            value: new Date()
        }
    },
    owner: {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
        optional: true
        autoValue: function(){
                  if (this.isInsert)
                             return Meteor.userId()
        },
        autoform:{
                      type: "select",
                      options: function(){
                                   return _.map(Meteor.users.find().fetch(), function(user) {
                                                        return {
                                                               label: user.emails[0].address,
                                                               value: user._id
                                                        };
                                         });
                             }
              }
      }
});

Posts.attachSchema(Schemas.Posts);

In lib/admin_config.js
AdminConfig = { collections: { Posts: {} } };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants