diff --git a/spec/autocompleteBehavior.js b/spec/autocompleteBehavior.js
index 80718cfa..1c5b4522 100644
--- a/spec/autocompleteBehavior.js
+++ b/spec/autocompleteBehavior.js
@@ -543,6 +543,67 @@ 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,
+ suggestionData = null;
+
+ beforeEach(function() {
+ input.autocomplete({
+ lookup: [{ value: 'Jamaica', data: 'J' }, { value: 'Jamaica2', data: 'J' }, { value: 'Jamaica3', data: 'J' }],
+ changeInputDisabled: true,
+ onSelect: function (suggestion) {
+ suggestionData = suggestion.data;
+ }
+ });
+
+ input.val('J');
+ instance = input.autocomplete();
+ });
+
+ it('Should NOT change input value when item is selected', function() {
+ instance.onValueChange();
+ instance.select(0);
+
+ expect(input.val()).toEqual('J');
+ });
+
+ it('Should NOT change input value when move down', function() {
+ instance.onValueChange();
+ instance.moveDown();
+
+ expect(input.val()).toEqual('J');
+ });
+
+ it('Should NOT change input value when move up', function() {
+ instance.onValueChange();
+ instance.moveUp();
+
+ expect(input.val()).toEqual('J');
+ });
+ });
+
it('Should use serviceUrl and params as cacheKey', function () {
var input = $(''),
instance,
diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js
index f2114bf5..804dc064 100644
--- a/src/jquery.autocomplete.js
+++ b/src/jquery.autocomplete.js
@@ -77,6 +77,8 @@
currentRequest: null,
triggerSelectOnValidInput: true,
preventBadQueries: true,
+ changeInputDisabled: false,
+ hideOnSelectDisabled: false,
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
},
@@ -696,7 +698,7 @@
select: function (i) {
var that = this;
- that.hide();
+ if (!that.options.hideOnSelectDisabled) { that.hide(); }
that.onSelect(i);
},
@@ -750,7 +752,10 @@
$(that.suggestionsContainer).scrollTop(offsetTop - that.options.maxHeight + heightDelta);
}
- that.el.val(that.getValue(that.suggestions[index].value));
+ if (!that.options.changeInputDisabled) {
+ that.el.val(that.getValue(that.suggestions[index].value));
+ }
+
that.signalHint(null);
},
@@ -760,7 +765,7 @@
suggestion = that.suggestions[index];
that.currentValue = that.getValue(suggestion.value);
- that.el.val(that.currentValue);
+ if (!that.options.changeInputDisabled) { that.el.val(that.currentValue); }
that.signalHint(null);
that.suggestions = [];
that.selection = suggestion;