Skip to content

Parse a pasted comma-separated string #9

@alfrekjv

Description

@alfrekjv

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions