Meteor + autoform example requested

javascript, meteor, node.js

Solution

I will try to make it simply.

First create the project and remove the `autopublish and insecure` packages

Second on the `/server/testform.js` put this.

TestCollection.allow({
  insert:function(){return true;},
  remove:function(){return true;},
  update:function(){return true;},
})

and the publish function

Meteor.publish("TestCollection", function () {
  return TestCollection.find();
});

More about allow/deny rules

Instead of `/both/testform.js`, put the collection declaration in `/lib/testform.js` as per Meteor best practice to make sure it is evaluated first.

TestCollection = new Mongo.Collection("TestCollection");

and the subscription.

if(Meteor.isClient){
     Meteor.subscribe('TestCollection')
}

now on `/client/testform.html`

put this.

<template name="testForm">
  {{> quickForm collection="TestCollection" id="insertTestForm" type="insert"}} 
</template>

now on `/client/testform.js` put the schema

TestCollection.attachSchema(new SimpleSchema({ //take this from docs.
  title: {
    type: String,
    label: "Title",
    max: 200
  },
  author: {
    type: String,
    label: "Author"
  },
  copies: {
    type: Number,
    label: "Number of copies",
    min: 0
  },
  lastCheckedOut: {
    type: Date,
    label: "Last date this book was checked out",
    optional: true
  },
  summary: {
    type: String,
    label: "Brief summary",
    optional: true,
    max: 1000
  }
})); 

NOTE

If you are new on Meteor/Javascript don't jump into complex packages likes this.

run this and see how they work.

meteor create --example todos 
meteor create --example local market

or take a look into the meteor tutorial

For Javascript this tutorial/guide help me a lot How to Learn Javascript properly

Problem

In the autoform docs, there are many snippets of examples, but I cannot get any of them to work. Principally because autoform, meteor, and finally JS are new to me. However, I am good at adapting examples, but couldn't find any simple examples. This is one I struggles with. Can I get a working full example of a simple autoform (or quickform) using collections? - Assume I have aldeed:autoform and aldeed:collection2 installed. Let's say my files are divided up into - both/testform.js - server/testform.js - client/testform.js - client/testform.js? And let's say I'm using a template called "testTemplate" and a collection called "testCollection" Thanks for the help.

Original source