From e5c457b69485dc015271a222bd6b6630462d1f01 Mon Sep 17 00:00:00 2001 From: Emerson Macedo Date: Fri, 21 Feb 2014 16:13:58 -0300 Subject: [PATCH] Added hideOnSelectDisabled option to prevent suggestion box to hide when select. Very useful when using changeInputDisabled is true. --- spec/autocompleteBehavior.js | 21 +++++++++++++++++++++ src/jquery.autocomplete.js | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/autocompleteBehavior.js b/spec/autocompleteBehavior.js index b5726f1..1c5b452 100644 --- a/spec/autocompleteBehavior.js +++ b/spec/autocompleteBehavior.js @@ -543,6 +543,27 @@ describe('Autocomplete', function () { expect(suggestionData).toBeNull(); }); + it('Should NOT hide suggestions when options.hideOnSelectDisabled is true and item is selected', function() { + $('.autocomplete-suggestions').remove(); + + var input = $(''), + instance, + suggestionData = null; + + input.autocomplete({ + lookup: [{ value: 'Jamaica', data: 'J' }], + hideOnSelectDisabled: true + }); + + input.val('J'); + instance = input.autocomplete(); + + instance.onValueChange(); + instance.select(0); + + expect($('.autocomplete-suggestions').is(':visible')).toBeTruthy(); + }); + describe('options.changeInputDisabled is true', function() { var input = $(''), instance, diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index c46dda5..804dc06 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -78,6 +78,7 @@ triggerSelectOnValidInput: true, preventBadQueries: true, changeInputDisabled: false, + hideOnSelectDisabled: false, lookupFilter: function (suggestion, originalQuery, queryLowerCase) { return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; }, @@ -697,7 +698,7 @@ select: function (i) { var that = this; - that.hide(); + if (!that.options.hideOnSelectDisabled) { that.hide(); } that.onSelect(i); },