I’m not sure how to approach my issue. Whether I should set my variables in my event to my spacebars syntax fields from my template or pass my returned event data into my helpers somehow.
Problem: I am trying to make it so users can click an “Add” button next to any of the people in a directory list (DirectoryList collection) and have that users information be added to a Contacts List collection. Its simply a messaging app where a person can scroll a directory of everyone and add users to their contacts list. Here are my files:
its obviously throwing me an error for the {{}} syntax in my event but i dont know what else to do or how to get this to work. Thought it might be able to inherit from the template those fields but i guess not?
Thank you for the suggestion. However. It doesnt seem to be currently working still. I copied it verbatim as you put. It isnt showing any errors in the console or the command prompt, just simple a button being clicked and nothing else.
Template.page_products.events({
'click .button--favorite': function() {
var currentUser = Meteor.userId();
var currentProduct = Products.findOne(this._id);
var currentProductTitle = currentProduct.title;
// I'm using update + addToSet because I'm storing all titles in one big array (attached to the user profile)
Meteor.users.update({_id: currentUser}, {$addToSet: {'profile.favorites': currentProductTitle}});
// This should work as well
ContactsList.insert({ title: currentProductTitle });
}
});
Hm… maybe doublecheck your collection-names?
Also I think you don’t need the event.preventDefault(); for a button. But its probably not the source of the problem, but give it a try.
And finally, throw some console.log statements in there to see which parts are working. (e.g. console.log(currentProductTitle); in my case)