Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Copy & Paste text thats contains delimiter #22

Closed
GooDer opened this issue Aug 2, 2011 · 5 comments
Closed

Copy & Paste text thats contains delimiter #22

GooDer opened this issue Aug 2, 2011 · 5 comments

Comments

@GooDer
Copy link

GooDer commented Aug 2, 2011

Text is not parsed when somebody paste text that contains delimiter (for example "foo, bar, test").

@deeleman
Copy link

A workaround for this would be to capture the onAddTag and then retrieve the previous value from the input field, pre-process the text string pasted and then import all the resulting tags conveniently stripped into different ones along with the previous ones. If you wrap up this logic in an utility function you will be able to leverage it in pages where there are more than one tagging input control.

Example:

var tidyTags = function(e){
    var tags = ($(e.target).val() + ',' + e.tags).split(',');
    var target = $(e.target);
    target.importTags('');
    for(var i = 0, z = tags.length; i<z; i++){
        var tag = tags[i];
        if(!target.tagExist(tag)){
            target.addTag(tag);
        }
    }
}

$('#tags_input').tagsInput({
    onAddTag : function(tag){
    if(tag.indexOf(',') > 0){
        tidyTags({target: '#tags_input', tags : tag});
         }
     }
});

@mrclay
Copy link

mrclay commented Apr 9, 2012

Small improvements to this workaround: 1. correctly handles pasted text with spaces like hello, world. 2. removes the placeholder text after splitting the tag.

var tidyTags = function(e) {
    var tags = ($(e.target).val() + ',' + e.tags).split(',');
    var target = $(e.target);
    target.importTags('');
    for (var i = 0, z = tags.length; i<z; i++) {
        var tag = $.trim(tags[i]);
        if (!target.tagExist(tag)) {
            target.addTag(tag);
        }
    }
    $('#' + target[0].id + '_tag').trigger('focus');
};

Also, you can call tidyTags with target: this (so it should be able to work for multiple tag inputs).

@earthmeLon
Copy link

Are there any plans on implementing this within jQuery-Tags-Input instead of using this as a work-around?

@earthmeLon
Copy link

Are there any plans to implement this natively instead of having to use this as a work-around?

@ghost
Copy link

ghost commented Jul 11, 2013

Implementing this workaround as one of my user wanted to copy/paste large amount of tags (delimited by a space). +1 for earthmeLon request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants