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

Commit 34af0ee

Browse files
committed
Merge pull request #210 from noahhendrix/patch-1
Allow tokenValue to be a function for more complex use cases
2 parents dfd9231 + d012cfb commit 34af0ee

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/jquery.tokeninput.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,7 @@ $.TokenList = function (input, url_or_data, settings) {
460460
});
461461

462462
// Store data on the token
463-
var token_data = {"id": item.id};
464-
token_data[settings.propertyToSearch] = item[settings.propertyToSearch];
463+
var token_data = item;
465464
$.data(this_token.get(0), "tokeninput", item);
466465

467466
// Save this token for duplicate checking
@@ -612,6 +611,9 @@ $.TokenList = function (input, url_or_data, settings) {
612611
// Update the hidden input box value
613612
function update_hidden_input(saved_tokens, hidden_input) {
614613
var token_values = $.map(saved_tokens, function (el) {
614+
if(typeof settings.tokenValue == 'function')
615+
return settings.tokenValue.call(this, el);
616+
615617
return el[settings.tokenValue];
616618
});
617619
hidden_input.val(token_values.join(settings.tokenDelimiter));
@@ -854,4 +856,4 @@ $.TokenList.Cache = function (options) {
854856
return data[query];
855857
};
856858
};
857-
}(jQuery));
859+
}(jQuery));

0 commit comments

Comments
 (0)