Can't insert data

hi meteorites, i’ve problem with this code. i dont know why this code cant work like i see in tutorial.

Template.body.events({
“submit .new-task”: function (event, template) {
// Prevent default browser form submit
event.preventDefault();

  // Get value from form element
  var text = event.target.text.value;
  var name=event.target.name.value;
  var place = event.target.place.value;


  // Insert a task into the collection
  Tasks.insert({
    text: text,

name: name,
place: place,
createdAt: new Date() // current time
});

  // Clear form
  event.target.text.value = "";

event.target.name.value="";
event.target.place.value="";
}
});

There are many possible causes of this. Most common ones that I can think of:

  • you removed insecure package but you didn’t define Tasks.allow on server-side so the server refuses to store your data. This will emit Access denied message in your browsers console. Read more here about allow API.
  • you’re using simple-schema package and the data you’re trying to insert doesn’t match your schema. This will emit an error in the server console which should tell you what the problem is.
2 Likes

thanks for your response…actually i’m not removed insecure and also not use simple schema…

Mh but your inputs are cleared if you submit the form? If yes, how did you define your Tasks variable?

thanks…i’m trying to run this code without “code //clear form” but the result still the same

Do you see any errors in either browser javascript console, or in the terminal where you ran meteor command? If yes, please paste them here, otherwise it’s impossible for us to investigate the problem.

Okay, the best will be if you post here your tasks.js where you’ve defined the collection and also a list of your packages (run meteor list).