tag-it
tag-it copied to clipboard
Pasting in nultiple tags (comma separated) is treated as a single tag
If you paste in: Tag1, Tag2 only a single tag "Tag1, Tag2" is created. I would have wanted it to see the comma and/or space and create tags for each item.
You can see this on the demo page: http://aehlke.github.com/tag-it/
This also works for spaces too. You could copy "tag1 tag2" and paste it in and it will be a single tag instead of two.
I was encountering this issue when a user would copy and paste a list of email addresses that could contain spaces and/or commas separating the email addresses. I was able to resolve this issue by adding some logic to the beforeTagAdded function:
beforeTagAdded: function(event, ui) {
if (!ui.duringInitialization) {
var tagArray = ui.tagLabel.split(/[\s,]+/);
if (tagArray.length>1) {
for (var i=0,max=tagArray.length;i<max;i++) {
$("#myTags").tagit("createTag", tagArray[i]);
}
return false;
}
}
}
I like this feature but it should reuse the same logic used for tokenizing individual keystroke input.
Sent from my iPhone
On Apr 3, 2013, at 2:36 PM, scottcanoni [email protected] wrote:
I was encountering this issue when a user would copy and paste a list of email addresses that could contain spaces and/or commas separating the email addresses. I was able to resolve this issue by adding some logic to the beforeTagAdded function:
beforeTagAdded: function(event, ui) { if (!ui.duringInitialization) { var tagArray = ui.tagLabel.split(/[\s,]+/); if (tagArray.length>1) { for (var i=0,max=tagArray.length;i<max;i++) { $("#myTags").tagit("createTag", tagArray[i]); } return false; } } }
Reply to this email directly or view it on GitHub.
Here's a solution that ties into the paste event. I put the code in around line 224, right before the keydown bind.
this.tagInput.bind('paste', function (event) {
// Set short timeout so .val() will have a value
setTimeout(function () {
var tagArray = that.tagInput.val().split(/[\n,]+/);
if (tagArray.length > 1) {
for (var i = 0; i < tagArray.length; i++) {
that.createTag(tagArray[i]);
}
}
}, 100);
});