Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Support for use of custom "tokenValue" field #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/jquery.tokeninput.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ $.TokenList = function (input, url_or_data, settings) {
.css({
outline: "none"
})
.attr("id", settings.idPrefix + input.id)
.attr("id", settings.idPrefix + input[settings.tokenValue])
.focus(function () {
if (settings.tokenLimit === null || settings.tokenLimit !== token_count) {
show_dropdown_hint();
Expand Down Expand Up @@ -460,7 +460,8 @@ $.TokenList = function (input, url_or_data, settings) {
});

// Store data on the token
var token_data = {"id": item.id};
var token_data = {};
token_data[settings.tokenValue] = item[settings.tokenValue];
token_data[settings.propertyToSearch] = item[settings.propertyToSearch];
$.data(this_token.get(0), "tokeninput", item);

Expand Down Expand Up @@ -492,7 +493,7 @@ $.TokenList = function (input, url_or_data, settings) {
token_list.children().each(function () {
var existing_token = $(this);
var existing_data = $.data(existing_token.get(0), "tokeninput");
if(existing_data && existing_data.id === item.id) {
if(existing_data && existing_data[settings.tokenValue] === item[settings.tokenValue]) {
found_existing_token = existing_token;
return false;
}
Expand Down Expand Up @@ -854,4 +855,4 @@ $.TokenList.Cache = function (options) {
return data[query];
};
};
}(jQuery));
}(jQuery));