jQuery.Tagify
jQuery.Tagify copied to clipboard
Parse a pasted comma-separated string
If a user pastes a comma-separated string, Tagify takes it as a single string.
I'm leaving this here, since I spent a fair amount of time trying to implement this functionality and it may help someone else. But, TBH, it should be good that the plugin handles it naturally.
var myTags = $("#tags").tagify();
$('body').bind("paste", function (e) {
if (e.target.id == 'tagify') { //
setTimeout(function () {
// uno, dos, tres
var tags = $(e.target).val().split(',');
$.each(tags, function (i, v) {
myTags.tagify('add', v);
});
}, 0);
}
});
To support the e.target.id == 'tagify' I had to tweak the _create method, to add the ID, like this;
_create: function () {
.....
this.tagInput = $("<input type='text'>")
.attr('placeholder', opts.addTagPrompt)
.attr('id', 'tagify') // << To support On paste method..
Cheers!