Ef Ge
Ef Ge

Reputation: 818

Call tag-it's createTag more than once

I am using tag-it to create Tags. It works like a charme, but I want to preset some tags. If I call

$('#tags').tagit('createTag', 'abc');

I get my Tag, but if I call this function a second time, there will be no second tag.

<script>
        $('#tags').tagit({
            placeholderText: "Such-Tags",
            afterTagAdded: function(){
                filter();           
            },
            afterTagRemoved: function(){
                filter();           
            },
             fieldName: "tagsField[]"
                    });

    {foreach item=tag from=$tags|default:null}
        $('#tags').tagit('createTag', '{$tag}');
    {/foreach}


    </script>

Whats the problem?

edit: if I add <li>Tag</li> I will get the following: enter image description here

Upvotes: 0

Views: 168

Answers (1)

Dimag Kharab
Dimag Kharab

Reputation: 4519

$(function(){
   $('#tags').tagit();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="http://aehlke.github.io/tag-it/js/tag-it.js"></script>

<link href='http://aehlke.github.io/tag-it/css/jquery.tagit.css' rel="stylesheet" type="text/css">
<link href='http://aehlke.github.io/tag-it/css/tagit.ui-zendesk.css' rel="stylesheet" type="text/css">

<ul id="tags">
     <!-- Existing list items will be pre-added to the tags -->
     <li>Tag1</li>
     <li>Tag2</li>
 </ul>

Upvotes: 1

Related Questions