Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.
Closed
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
22 changes: 20 additions & 2 deletions src/jquery.tokeninput.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var DEFAULT_SETTINGS = {
jsonContainer: null,
contentType: "json",

// Prepopulation settings
// Prepopulation settings
prePopulate: null,
processPrePopulate: false,

Expand All @@ -40,6 +40,7 @@ var DEFAULT_SETTINGS = {
tokenDelimiter: ",",
preventDuplicates: false,
tokenValue: "id",
createTokens: false,

// Callbacks
onResult: null,
Expand Down Expand Up @@ -283,6 +284,13 @@ $.TokenList = function (input, url_or_data, settings) {
add_token($(selected_dropdown_item).data("tokeninput"));
hidden_input.change();
return false;
} else if (settings.createTokens && $.trim($(this).val()).length > 0) {
var data = {}
data[settings.tokenValue] = '__created';
data[settings.propertyToSearch] = $.trim($(this).val());
add_token(data);
hidden_input.change();
return false;
}
break;

Expand Down Expand Up @@ -534,7 +542,12 @@ $.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 (settings.createTokens && item[settings.tokenValue] == '__created') {
if (existing_data && existing_data[settings.propertyToSearch] == item[settings.propertyToSearch]) {
found_existing_token = existing_token;
return false;
}
} else if(existing_data && existing_data[settings.tokenValue] === item[settings.tokenValue]) {
found_existing_token = existing_token;
return false;
}
Expand Down Expand Up @@ -659,6 +672,9 @@ $.TokenList = function (input, url_or_data, settings) {
if(typeof settings.tokenValue == 'function')
return settings.tokenValue.call(this, el);

if (settings.createTokens && el[settings.tokenValue] == "__created") {
return "__created:" + el[settings.propertyToSearch];
}
return el[settings.tokenValue];
});
hidden_input.val(token_values.join(settings.tokenDelimiter));
Expand All @@ -685,13 +701,15 @@ $.TokenList = function (input, url_or_data, settings) {

function show_dropdown_searching () {
if(settings.searchingText) {
selected_dropdown_item = null;
dropdown.html("<p>"+settings.searchingText+"</p>");
show_dropdown();
}
}

function show_dropdown_hint () {
if(settings.hintText) {
selected_dropdown_item = null;
dropdown.html("<p>"+settings.hintText+"</p>");
show_dropdown();
}
Expand Down