tag-it icon indicating copy to clipboard operation
tag-it copied to clipboard

Pasting in nultiple tags (comma separated) is treated as a single tag

Open kleesman opened this issue 12 years ago • 4 comments

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/

kleesman avatar Jan 14 '13 17:01 kleesman

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.

adamkdean avatar Feb 23 '13 14:02 adamkdean

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;
            }       
        }
    }

scottcanoni avatar Apr 03 '13 18:04 scottcanoni

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.

aehlke avatar Apr 03 '13 21:04 aehlke

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);
            });

jgimness avatar Mar 30 '16 14:03 jgimness