I'm encountering an issue where I can't seem to add comments to a specific post. The comments aren't being inserted into the mongo database.
Comments = new Mongo.Collection('comments');
Template.comments.helpers({
'comment': function(){
console.log(this._id);
return Comments.find();
}
});
Template.addComment.events({
'click button':function(event){
event.preventDefault();
var madeBy = Meteor.user().username;
var comment = document.getElementById('mycomment').value;
var currentPost = this._id;
Comments.insert({
comment:comment,
createdAt:new Date(),
madeBy:madeBy,
});
document.getElementById('mycomment').value='';
}
});
Checkout the HTML code below for the comment page:
<template name="comments">
<h2><b>{{name}}</b></h2>
{{> addComment}}
<ul>
{{#each comment}}
<li>{{comment}}</li>
{{/each}}
</ul>
</template>
<template name='addComment'>
<input type='text' placeholder='Add comment here' name='comment' id ='mycomment'>
<button class="btn btn" type="button" id='btn'>Comment</button>
</template>
In the template, {{name}} is used to represent the post's name to which the comment is being added. Can someone provide assistance with this issue? Thank you.