Last active
February 27, 2016 17:22
-
-
Save patrickleet/e1c7a05eca86f536e3d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Context should be the object you are tagging --> | |
<template name="tagInput"> | |
<select class='tag-input' name='tags[]' multiple="multiple"> | |
{{#each tags}} | |
<option value="{{this}}" selected="true">{{this}}</option> | |
{{/each}} | |
</select> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.tagInput.rendered = function () { | |
var that = this; | |
this.$('.tag-input').selectize({ | |
valueField: 'name', | |
labelField: 'name', | |
searchField: ['name'], | |
create: function(input, cb) { | |
console.log('create tag: ', input) | |
Items.addTag(input, {_id: that.data._id}); | |
var tag = Meteor.tags.findOne({collection: 'items', name: input}); | |
if (cb) { | |
cb(tag); | |
} | |
return tag; | |
}, | |
options: Meteor.tags.find({collection: 'items'}).fetch(), | |
render: { | |
item: function(item, escape) { | |
return '<div>' + | |
(item.name ? '<span class="name">' + escape(item.name) + '</span>' : '') + | |
'</div>'; | |
}, | |
option: function(item, escape) { | |
var name = item.name; | |
var caption = item.nRefs; | |
return '<div>' + | |
'<span class="name">' + escape(name) + '</span> ' + | |
(caption ? '<span class="badge">' + escape(caption) + '</span>' : '') + | |
'</div>'; | |
} | |
}, | |
onItemAdd: function(value, $item) { | |
console.log('add tag: ', value); | |
Items.addTag(value, {_id: that.data._id}); | |
}, | |
onItemRemove: function(value) { | |
console.log('remove tag: ', value); | |
Items.removeTag(value, {_id: that.data._id}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This would make for a nice Meteorpad.