From 9d8118fa6b7eb69011bbc766e2e7676e10b894d7 Mon Sep 17 00:00:00 2001 From: Tomas Kirda Date: Sun, 21 Sep 2014 18:00:12 -0500 Subject: [PATCH] Call onSearchStart and onSearchComplete for local search. Fixes #241 --- src/jquery.autocomplete.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 6ae0029..7b81649 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -533,6 +533,10 @@ options.params[options.paramName] = q; params = options.ignoreParams ? null : options.params; + if (options.onSearchStart.call(that.element, options.params) === false) { + return; + } + if (that.isLocal) { response = that.getSuggestionsLocal(q); } else { @@ -546,10 +550,8 @@ if (response && $.isArray(response.suggestions)) { that.suggestions = response.suggestions; that.suggest(); + options.onSearchComplete.call(that.element, q, response.suggestions); } else if (!that.isBadQuery(q)) { - if (options.onSearchStart.call(that.element, options.params) === false) { - return; - } if (that.currentRequest) { that.currentRequest.abort(); } @@ -572,6 +574,8 @@ }).fail(function (jqXHR, textStatus, errorThrown) { options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown); }); + } else { + options.onSearchComplete.call(that.element, q, result.suggestions); } },