Search code examples
javascriptjquerytag-it

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?


Solution

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