testStack201541
testStack201541

Reputation: 119

javascript tag-it allowed tags

I need to allow users select ONLY allowed tags in tagSource.

Currently I have that:

var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
$("#myTags").tagit({
    tagSource: sampleTags 
});

tag-it in GitHub

Tag-it! Usage Examples

Can you help me please with that?

Upvotes: 2

Views: 163

Answers (1)

Santosh Ram Kunjir
Santosh Ram Kunjir

Reputation: 1082

check this it will work

 var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
    $("#myTags").tagit({
        availableTags: sampleTags,
         afterTagAdded: function (event, ui) {
        if ($.inArray(ui.tagLabel, sampleTags) == -1) {
            $("#myTags").tagit("removeTagByLabel", ui.tagLabel);
        }
    }
    });

Upvotes: 1

Related Questions