This is topic is the continuance of the following topic.
In the post
submit page I’d like to add checkboxes with tags name right after it.
I want to list up all existing tag, so that I can select tag by ticking checkboxes.
Related parts:
tags.js:
Tags = new Mongo.Collection('tags');
Tags.allow({
update: function (userId, tag) {
return ownsDocument(userId, tag);
},
remove: function (userId, tag) {
return ownsDocument(userId, tag);
}
});
Meteor.methods({
tagInsert: function (tagAttributes) {
check(Meteor.userId(), String);
check(tagAttributes, {
postId: String,
title: String
});
var user = Meteor.user();
var tag = _.extend(tagAttributes, {
userId: user._id,
author: user.username,
submitted: new Date()
});
var tagId = Tags.insert(tag);
return {
_id: tagId
};
}
});
post_submit.html:
<template name="postSubmit">
<form class="main form page">
<div class="form-group">
<label class="control-label" for="title">Title</label>
<div class="controls">
<input name="title" id="title" type="text" value="" placeholder="Name your post" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="control-label" for="body">Body</label>
<div class="controls">
<textarea name="body" id="body" value="" placeholder="Post content" class="form-control"
rows="3"></textarea>
</div>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
</template>
post_submit.js:
Template.postSubmit.events({
'submit form': function (e) {
e.preventDefault();
var post = {
title: $(e.target).find('[name=title]').val(),
body: $(e.target).find('[name=body]').val()
};
Meteor.call('postInsert', post, function (error, result) {
// display the error to the user and abort
if (error)
return alert(error.reason);
Router.go('postPage', {_id: result._id});
});
}
});
To do:
- I will need to add
var tags = Tags.find()
inpost_submit.js
if I’m not mistaken as I will need alltags
to list with check boxes on thepost
submit page, but I’m sure how to declare it in right way. - I need to add a snippet in
page_submit.html
withinput type="checkbox"
by listing up alltags
. Don’t know how to do that. By ticking check box it should apply that corresponding tag.
Thanks.