From dc462d4ef234d006cd5b15649232d7fa36def805 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 8 Nov 2017 22:09:20 -0500 Subject: [PATCH] Create an event to manually trigger the search It may be useful to ask this plugin to show it's suggestions immediately, perhaps from a virtual keyboard that doesn't send real keydown events or some other trigger. This change creates a new 'autocomplete.popup' event that can be triggered through jQuery's trigger() routine to request it immediately do the search and reveal the results. --- jquery.auto-complete.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jquery.auto-complete.js b/jquery.auto-complete.js index 330e04a..065b001 100644 --- a/jquery.auto-complete.js +++ b/jquery.auto-complete.js @@ -103,7 +103,12 @@ else that.sc.hide(); } - + // manually trigger the autocomplete popup + that.on('autocomplete.popup', function(e) { + var val = that.val(); + o.source(val,suggest); + }); + that.on('keydown.autocomplete', function(e){ // down (40), up (38) if ((e.which == 40 || e.which == 38) && that.sc.html()) { @@ -143,7 +148,7 @@ if (part in that.cache && !that.cache[part].length) { suggest([]); return; } } } - that.timer = setTimeout(function(){ o.source(val, suggest) }, o.delay); + that.timer = setTimeout(function(){ that.trigger('autocomplete.popup') }, o.delay); } } else { that.last_val = val;