diff --git a/admin/js/tokeninput.js b/admin/js/tokeninput.js index 4f03c440..c571299e 100755 --- a/admin/js/tokeninput.js +++ b/admin/js/tokeninput.js @@ -502,6 +502,10 @@ $.TokenList = function (input, url_or_data, settings) { item[settings.propertyToSearch] = input_box.val(); } + if (!item) { + return false; + } + // See if the token already exists and select it if we don't want duplicates if(token_count > 0 && settings.preventDuplicates) { var found_existing_token = null; @@ -803,7 +807,7 @@ $.TokenList = function (input, url_or_data, settings) { // Attach the success callback ajax_params.success = function(results) { if($.isFunction(settings.onResult)) { - results = settings.onResult.call(hidden_input, results); + results = settings.onResult.call(hidden_input, results, query); } cache.add(cache_key, settings.jsonContainer ? results[settings.jsonContainer] : results); @@ -822,7 +826,7 @@ $.TokenList = function (input, url_or_data, settings) { }); if($.isFunction(settings.onResult)) { - results = settings.onResult.call(hidden_input, results); + results = settings.onResult.call(hidden_input, results, query); } cache.add(cache_key, results); populate_dropdown(query, results); diff --git a/admin/user.php b/admin/user.php index 7b0b1ed7..227d9e14 100644 --- a/admin/user.php +++ b/admin/user.php @@ -1,6 +1,5 @@ @@ -19,5 +18,6 @@ include 'menu.php'; diff --git a/admin/write-js.php b/admin/write-js.php index d09c6c19..8b370446 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -77,7 +77,22 @@ $(document).ready(function() { noResultsText : '', prePopulate : tagsPre, - onResult : function (result) { + onResult : function (result, query) { + if (!query) { + return result; + } + + if (!result) { + result = []; + } + + if (!result[0] || result[0]['id'] != query) { + result.unshift({ + id : query, + tags : query + }); + } + return result.slice(0, 5); } });