0

the following code snippet in the tutorial for Pieces (http://apostrophecms.org/docs/tutorials/getting-started/reusable-content-with-pieces.html) gives the type error : self[name] is not a function - on line 1031 of lib/modules/apostrophe-docs/lib/cursor.

The error happens when clicking on the save button for adding a new person or saving the piece.

I understand this may happen because the object is not actually what I am thinking it is or because it´s returning a null value. Both seem unlikely.

As I am following the tutorial step by step I have only browsed through the cursor part.

The people.index.js file is the following:

module.exports = {
    extend: 'apostrophe-pieces',
    name: 'person',
    label: 'Person',
    pluralLabel: 'People',
    addFields: [
        {
            name: 'title',
            label: 'Full Name',
            type: 'string',
            required: true,
            contextual: true
        },
        {
            name: 'firstName',
            label: 'First Name',
            type: 'string',
            required: true
        },
        {
            name: 'lastName',
            label: 'Last Name',
            type: 'string',
            required:true
        },
        {
            name: 'body',
            label: 'Biography',
            type: 'area',
            options: {
                widgets: {
                    'apostrophe-rich-text': {
                        controls: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
                    },
                    'apostrophe-images': {}
                }
            }
        },
        {
            name: 'phone',
            label: 'Phone',
            type: 'string'
        },
        {
            name: 'thumbnail',
            label: 'Thumbnail',
            type: 'singleton',
            widgetType: 'apostrophe-images',
            options: {
                limit: 1,
                minSize: [ 200, 200 ],
                aspectRatio: [ 1, 1 ]
            }
        }
    ],
    arrangeFields: [
        {
            name: 'contact',
            label: 'Contact',
            fields: [ 'firstName', 'lastName', 'phone' ]
        },
        {
            name: 'admin',
            name: 'Admin',
            fields: [ 'slug', 'published', 'tags' ]
        },
        {
            name: 'content',
            name: 'Biographical',
            fields: [ 'thumbnail', 'body' ]
        }
    ],
    construct: function(self, options) {
        var superPushAssets = self.pushAssets;
        self.pushAssets = function() {
          superPushAssets();
          self.pushAsset('stylesheet', 'always', { when: 'always' });
        };
    },
    construct: function(self, options) {
        self.beforeSave = function(req, piece, options, callback) {
          piece.title = piece.firstName + ' ' + piece.lastName;
          return callback();
        };
    }
};
  • I'm the lead architect of Apostrophe; happy to help. Since you are following the tutorial, would you be comfortable posting a github link to your project so I can try it out? I haven't seen this error, but I bet it'll be immediately apparent if I have all of the pieces. – Tom Boutell Feb 17 '17 at 01:47
  • Sure, here´s the repo: https://github.com/newdesignideas/veebidisainer-project (I wiped my database after encountering this error - when I played around trying to get Apostrophe to play nice with MongoDB with authcontrol). Ended up binding it to 127.. / localhost like you advised on github. – robert-jakobson Feb 17 '17 at 10:44
  • Hmm, I fired up this project and added a user, logged in, created a person and saved them with no trouble. Can you provide more details on how to duplicate the issue? ( As for mongo with auth, there's an example here: http://apostrophecms.org/docs/tutorials/howtos/deploying-apostrophe-in-the-cloud.html ) – Tom Boutell Feb 18 '17 at 14:19
  • I saw the code that you did `construct` function twice ! Try bring self.beforeSave code below self.pushAssets function . Remove second `construct` module function. That should work out – Amin Shazrin Sep 15 '18 at 14:43

0 Answers0