Skip to content

Commit

Permalink
don't spin when value is already in list
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Sep 25, 2014
1 parent da23aad commit 15c2232
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/wq/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ var _cache = {};
auto.update = function($datalist, value) {
var url = $datalist.data('url'),
param = $datalist.data('query') || 'q',
min = $datalist.data('min') || 3;
min = $datalist.data('min') || 3,
exists = $datalist.find(
'option[value="' + value.replace('"', "'") + '"]'
).length;

// Only continue if a long enough value is present
if (!value || value.length < min) {
Expand All @@ -65,9 +68,11 @@ auto.update = function($datalist, value) {
}

// Load results via AJAX
spin.start();
if (!exists)
spin.start();
json.get(url, function(result) {
spin.stop();
if (!exists)
spin.stop();
if (!result.list)
result = {'list': result};
result.count = result.count || result.list.length;
Expand Down

0 comments on commit 15c2232

Please sign in to comment.