0

this is my code :

$("#AddFriendToGroup" + GroupID).tagit({
                    allowDuplicates: false,
                    readOnly: false,
                    autocomplete: { source: function (request, showChoices) {
                        $.ajax({
                            type: 'POST',
                            url: 'ChatPageTest.aspx/tagFriendAutocomplete',
                            data: "{'ClientID':'" + $("#UserID").val() + "','ClientName': '" + request.term + "'}",
                            contentType: 'application/json; charset=utf-8',
                            dataType: 'json',
                            success: function (data) {
                                returndData = data;
                                showChoices($.map(data.d, function (item) {

                                    return {
                                        label: item.split('-')[0],
                                        val: item.split('-')[1]
                                    }
                                }))
                            },
                            error: function (xhr) {
                                alert("responseText: " + xhr.responseText);
                            }
                        });
                    }
                    },
                    beforeTagAdded: function (event, ui) {

                        if ($.inArray(ui.tagLabel, returndData) == -1) return false;
                    },
                    minLength: 2
                }); // tagit

server side :

public static string[] tagFriendAutocomplete(int ClientID,string ClientName)
{
    List<string> Friends = new List<string>();
    string query = "select fr.FRIEND_ID,c.[USER_NAME] from clients c inner join friends fr on c.CLIENT_ID=fr.FRIEND_ID and fr.CLIENT_ID=" + ClientID + " and c.[USER_NAME] like '%" + ClientName + "%' ";

    DataTable dt = new SQLHelper(SQLHelper.ConnectionStrings.WebSiteConnectionString).getQueryResult(query);
    if (dt.Rows.Count > 0)
    { 
       for(int i=0;i<dt.Rows.Count;i++)
       {
          Friends.Add(string.Format("{0}-{1}",dt.Rows[i]["USER_NAME"], dt.Rows[i]["FRIEND_ID"]));
        }
    }

    return Friends.ToArray();
}

my problem is when i try to add a new tag from the autocomplete suggestion the new tag wont be added i guess my problem is in beforeTagAdded function can anyone help me

Sora
  • 2,465
  • 18
  • 73
  • 146

1 Answers1

0
.tagit("add", {label: 'tag', value: 12})

i found this in documentation check it out

also it seems you should enable allowNewTags option to TRUE, maybe this is causing an error, cause you trying inserting new tag while the plugin do not allow that, check options too

itsme
  • 48,972
  • 96
  • 224
  • 345