jQuery tag-it only allow available tags

jquery, tag-it

Solution

Posted on behalf of OP:

I'm using the beforeTagAdded function I found my answer:

        tagSource: function(request, response) 
        {
            $.ajax({
                data: { term:request.term },
                type: "POST",
                url:        "/site2/message/users.php",
                dataType:   "json",
                 success: function( data ) {
                     array = data;
                    response( $.map( data, function( item ) {

                        return {
                            label:item,
                            value: item
                        }
                        }));
                    }

            });
            },
        tagLimit :3,
        autocomplete: {delay: 0, minLength: 1},
        beforeTagAdded: function(event, ui) {
            if(array.indexOf(ui.tagLabel) == -1)
            {
                return false;
            }
            if(ui.tagLabel == "not found")
            {
                return false;
            }

        },

Problem

i use jQuery tag-it in my script: ``` $("#user_autocomplete").tagit({ tagSource: function (request, response) { $.ajax({ data: { term: request.term }, type: "POST", url: "/site2/message/users.php", dataType: "json", success: function (data) { response($.map(data, function (item) { return { label: item, value: item } })); } }); }, tagLimit: 3, autocomplete: { delay: 0, minLength: 1 }, }); ``` In this case, all input fields are confirmed. But I want only the fields that are available to be added. How to do it?

Original source