From 3b0cd28635c3e83e499bcc3f20dde1a42abe9b6a Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 27 Aug 2015 14:22:05 -0400 Subject: [PATCH] Fixed bug: multiple autocompletes on one page not handled properly. --- themes/bootstrap3/js/common.js | 60 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index 70cc9d5c561..29d375dc37f 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -352,38 +352,40 @@ $(document).ready(function() { }); // Search autocomplete - $('.autocomplete').typeahead( - { - highlight: true, - minLength: 3 - }, { - displayKey:'val', - source: function(query, cb) { - var searcher = extractClassParams('.autocomplete'); - $.ajax({ - url: path + '/AJAX/JSON', - data: { - q:query, - method:'getACSuggestions', - searcher:searcher['searcher'], - type:$('#searchForm_type').val() - }, - dataType:'json', - success: function(json) { - if (json.status == 'OK' && json.data.length > 0) { - var datums = []; - for (var i=0;i<json.data.length;i++) { - datums.push({val:json.data[i]}); + $('.autocomplete').each(function (i, element) { + $(element).typeahead( + { + highlight: true, + minLength: 3 + }, { + displayKey:'val', + source: function(query, cb) { + var searcher = extractClassParams(element); + $.ajax({ + url: path + '/AJAX/JSON', + data: { + q:query, + method:'getACSuggestions', + searcher:searcher['searcher'], + type:searcher['type'] ? searcher['type'] : $('#searchForm_type').val() + }, + dataType:'json', + success: function(json) { + if (json.status == 'OK' && json.data.length > 0) { + var datums = []; + for (var i=0;i<json.data.length;i++) { + datums.push({val:json.data[i]}); + } + cb(datums); + } else { + cb([]); } - cb(datums); - } else { - cb([]); } - } - }); + }); + } } - } - ); + ); + }); $('#searchForm_type').change(function() { var query = $('#searchForm_lookfor').val(); $('#searchForm_lookfor').focus().typeahead('val', '').typeahead('val', query); -- GitLab