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

Commit d012cfb

Browse files
committed
Store the entire item from the server response, not just the name and id. Then allow the tokenValue to be a function that is passed the item, and returns a string. This allows more complex data than just the id to be sent to the server.
1 parent c21349a commit d012cfb

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)