This post is being ignored -> Adding checkboxes


#1

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:

  1. I will need to add var tags = Tags.find() in post_submit.js if I’m not mistaken as I will need all tags to list with check boxes on the post submit page, but I’m sure how to declare it in right way.
  2. I need to add a snippet in page_submit.html with input type="checkbox" by listing up all tags. Don’t know how to do that. By ticking check box it should apply that corresponding tag.

Thanks.


#3

Please someone point me out what’s wrong with this post?


#4

@tenzan

There is nothing wrong at all with your post. This post and your initial post are cogent, important.

As for the post being ignored, my take is that few people understand, at this point, many-to-many with Mongo. I’m not aware of any mainstream language evolving to discuss many-to-many with Mongo and no simplified techniques / packages / patterns have appeared – with the possible exception of Publish Composite with which I have yet to experiment. So, what we get is people with no real experience telling us only we can’t say “many-to-many”. It amuses me.

I, for one, would value your continued writing and hope that people with concrete knowledge and experience in this area would chime in.

All the best,

Steve


#5

From the UX point of view, how many tags do you plan to have? 10, 50, 200? Have you thought of multiply select field instead of checkboxes?


#6

@steinitz Thanks for recalling me this post. I forgot about it :smile:

I’m still wondering why the case I brought is so confused. This is a classical posts and tags example. Let’s put a side the term many-to-many, do you mean it’s not easy to implement post has many tags and tag has many posts in Meteor?

@brajt Oh, thanks for the idea - I’ve never thought about it. I assume, you mean one field, where I will enter already existing tags. I like it too, but I think I will need to implement autocomplete as I type a tag. Is it possible? On the other side I’m still interested checkbox implementation.


#7

Yes, the common way to do it is with autocomplete. You can also enable or disable adding new tags by the user in the same select field.

You can see an example implementation here (multiple select boxes): https://select2.github.io/examples.html


#8

Thanks. I see this is not a Meteor-specific, but general. I’ll bookmark the link.


#9

@steinitz

By the way, though we I called here many-to-many relations for posts and tags their schema still will look like

posts : { _id: String, title: String, body: String }

tags : { title: String, post_id: String }

(Ref.: Defining schemas for 2 models in `many-to-many` relationship)

So, I meant to implement checkboxes from that contest. I had to mention about it from the beginning.