Skip to content Skip to sidebar Skip to footer

Meteor Autoform Package With Collection2 Does Not Submit The Form

I am using using collection2 and autoform with one level nested schemas Node = new Meteor.Collection('node',{ schema: new SimpleSchema({ content: { type: String,

Solution 1:

Since created and modified are required fields, it's most likely not submitting because those fields are missing from the form, which means the form is invalid. There are actually a few different ways you can solve this:

  1. Make them optional (probably not what you want)
  2. Use a different schema, one without those two fields, for the schema attribute of the autoform.
  3. Add a "before method" hook that sets those two fields in the submitted doc.
  4. Use autoValue to generate the values for those two fields.

Since created and modified dates are fairly easy to do with autoValue, I would do it that way. Something like this:

created: {
    type: Date,
    label: "Created Date",
    autoValue: function () {
        if (this.isInsert) {
          returnnewDate;
        } else {
          this.unset();
        }
    }
},
modified: {
    type: Date,
    label: "Modified Date",
    autoValue: function () {
        if (this.isInsert) {
          this.unset();
        } else {
          returnnewDate;
        }
    }
}

Also, to help figure out issues like this more easily while developing, I recommend enabling debug mode.

Solution 2:

Have you allowed inserts/updates on your collection? See http://docs.meteor.com/#dataandsecurity.

I bet if you run the two commands below, it'll work.

meteor add insecure
meteor add autopublish 

Now try your submit.

If it does work, turn autopublish and insecure back off

meteor remove insecure
meteor remove autopublish

Then write your allow methods, e.g.

Node.allow({
  insert: function (userId, nodeDoc) {
    // write some logic to allow the insert returntrue;
  }
});

Post a Comment for "Meteor Autoform Package With Collection2 Does Not Submit The Form"