UPDATE:
I have recently included additional code for clarification, marked as * NEW *. To explain the functionality of this code - it involves inputting a series of data into a collection named posts
. The displayed output on the postsList template occurs when the timeToEnable field is less than the current time. This enables post delays based on specified dates using this javascript time picker. The issue I am facing lies within the file /client/posts/post_edit.js
where I am attempting to set the value of one of the pickers from data in the collection. However, I am uncertain on how to retrieve this data in JavaScript compared to HTML where "{{fieldHere}}" and the postsList template helper are used.
Hopefully, this updated code and information provides better insight into the situation.
ORIGINAL QUESTION.
I have a form that submits 5 fields to a posts
collection. On the edit page, the title and content fields auto-populate. However, there are two separate Date/Time pickers. There exists a function that can correctly set the Date/Time pickers with specific data from the posts
collection while editing. Due to the specific format in which date/time data is stored (e.g., 2015-05-25T17:50:00.000Z
), I have created separate fields in the collection for day, month, and year to utilize a datepicker function.
This particular function will facilitate setting the Date picker.
picker.set('select', new Date(year, month, date));
The challenge arises when trying to retrieve the year, month, and date data based on the ID of the post being edited. While I can display them in HTML using {{title}}, I am unsure about identifying the ID, accessing that post in the collection, and utilizing picker.set
accordingly.
Below is the code representing my progress so far:
Client
/client/posts/post_submit.js
Template.postSubmit.events({
'submit form': function(e){
e.preventDefault();
var post = {
title: $(e.target).find('[name=title]').val(),
postContent: $(e.target).find('[name="postContent"]').val(),
timeToEnable: new Date(year, month, day, hours, minutes),
timeDisplay: timeDisplay,
year: year,
month: month,
day: day,
hours: hours
};
// console.log(post.timeToEnable);
Meteor.call('postInsert', post, function(error, result) {
// display the error to the user and abort
if (error){
return alert(error.reason);
}
// show this result but route anyway
if (result.postExists){
alert('This link has already been posted');
}
Router.go('postPage', {_id: result._id});
});
}
});
/client/posts/posts_list.html
* NEW *
<template name="postsList">
<div class="posts page">
{{#each posts}}
{{> postItem}}
{{/each}}
</div>
</template>
Server ~/server/publications.js`
Meteor.publish('posts', function() {
return Posts.find();
});
In conclusion, I would appreciate assistance regarding retrieving the collection fields for posts
in postEdit when rendering the template to set the value of the day input picker.
Thank you in advance for your help.