Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

dylan kane
dylan kane
2,772 Points

My meteor autoform wont submit, tried everything, what's wrong?

I am using a couple of packages in a meteor web app, including aldeed:autoform and aldeed:collection2. Together I made a schema and attached it to a database. I then auto generated a form for it, which includes a submit button. The submit button worked perfectly when I first generated it, but not when I run my meteor app it will not work once I press submit. I checked the git linked to the folder and it doesnt look like there have been any changes made that would effect this. Is there a way that I can debug the autoform? I'm not sure what to do, any help would be great.

Here is the relevant code in my main.js file:

CreateLobby = new Mongo.Collection("createlobby");

CreateLobbySchema = new SimpleSchema({
  game: {
    type: String,
    label: "Game"
  },
  console: {
    type: String,
    label: "Console"
  },
  players: {
    type: Number,
    label: "Players"
  },
  mic: {
    type: Boolean,
    label: "Mic"
  },
  note: {
    type: String,
    label: "Note"
  },
  gamertag: {
    type: String,
    label: "Gamertag"
  }
});

CreateLobby.attachSchema( CreateLobbySchema );

Meteor.subscribe("createlobby");

and on the server main.js:

CreateLobby = new Mongo.Collection("createlobby");

CreateLobby.allow({
  'insert': function (userId,doc) {
    return true;
  }
});

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

and html to call it:

{{#autoForm collection="CreateLobby" id="insertLobbyForm"         type="insert"}}
  <fieldset>
    {{> afQuickField name="game"}}
    {{> afQuickField name="console"}}
    {{> afQuickField name="players"}}
    {{> afQuickField name="mic"}}
    {{> afQuickField name="note" rows=2}}
    {{> afQuickField name="gamertag"}}
    <div>
      <button type="submit" class="btn btn-primary">Submit</button>
      <button type="reset" class="btn btn-default">Reset</button>
    </div>
  </fieldset>
{{/autoForm}}

1 Answer

Talgat Amanbayev
Talgat Amanbayev
3,983 Points

Hello again, Dylan. This time again, in Meteor 1.3 you need to user other feature related to imports.

Here is a link to official forum related to this

In your server file (for example CreateLobby.js), you need to define your collection in a way similar to this:

export const CreateLobby = new Mongo.Collection("createlobby");
// rest of your code for server side goes here as usual

and in your client file where you need to use this collection:

import { CreateLobby } from '../path/to/your/file/CreateLobby.js';

then you go like you usually would, i.e. CreateLobby.attachSchema(...);

I hope this helps!