2

I’ve been creating a basic contact form following the Apostrophe CMS documentation and have got it working but now want to remove the “excess” code by using the apostrophe-pieces-submit-widgets module. I have tried using it in both my app.js file and creating a contact-form-submit-widgets module and I receive the following error:

The type apostrophe-pieces-submit-widgets is not defined.

This is a brand new blank project and the only code I've added so far is the contact-form module schema which is as follows:

const async = require('async');

module.exports = {
  extend: 'apostrophe-pieces',
  name: 'contact-form',
  label: 'Contact Form',
  alias: 'contactForm',
  addFields: [
    {
      name: 'title',
      type: 'string',
      label: 'Full Name',
      required: true
    },
    {
      name: 'email',
      type: 'string',
      label: 'Email',
      required: true
    },
    {
      name: 'message',
      type: 'string',
      label: 'Message',
      textarea: true,
      required: true
    }
  ],
  permissionsFields: false,

  construct: (self, options) => {
    self.setSubmitSchema = () => {
      self.submitSchema = self.apos.schemas.subset(self.schema, [
        'title',
        'email',
        'message'
      ]);
    };

    self.submit = (request, callback) => {
      const piece = {};
      return async.series([
        callback => self.apos.schemas.convert(request, self.schema, 'form', request.body, piece, callback),
        callback => self.insert(request, piece, { permissions: false }, callback)
      ], callback);
    };
  },

  afterConstruct: self => {
    self.setSubmitSchema();
  }
};

Any help would be hugely appreciated.

Wayne

Wayne Haffenden
  • 160
  • 1
  • 5
  • Are you sure you have `apostrophe-pieces-submit-widgets` installed locally? You've run `npm install apostrophe-pieces-submit-widgets` – Stuart Romanek Dec 17 '18 at 03:04

0 Answers0