mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-12 16:26:37 +00:00
Implement preserve input option. Closes #164.
This commit is contained in:
parent
dfd7f44509
commit
54f24951e3
@ -52,6 +52,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
|
||||
* `orientation`: Default `bottom`. Vertical orientation of the displayed suggestions, available values are `auto`, `top`, `bottom`.
|
||||
If set to `auto`, the suggestions will be orientated it the way that place them closer to middle of the view port.
|
||||
* `groupBy`: property name of the suggestion `data` object, by which results should be grouped.
|
||||
* `preserveInput`: if `true`, input value stays the same when navigating over suggestions. Default: `false`.
|
||||
|
||||
Autocomplete instance has following methods:
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*jslint vars: true*/
|
||||
/*jslint vars: true*/
|
||||
/*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $*/
|
||||
|
||||
describe('Autocomplete Async', function(){
|
||||
@ -39,7 +39,7 @@ describe('Autocomplete Async', function(){
|
||||
});
|
||||
});
|
||||
|
||||
describe('Autocomplete Async', function() {
|
||||
describe('Autocomplete Async', function () {
|
||||
var input = document.createElement('input'),
|
||||
completeQuery,
|
||||
mockupSuggestion = { value: 'A', data: 'A' },
|
||||
@ -688,3 +688,47 @@ describe('Autocomplete', function () {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('When options.preserveInput is true', function() {
|
||||
var input = $('<input />'),
|
||||
instance,
|
||||
suggestionData = null;
|
||||
|
||||
beforeEach(function() {
|
||||
input.autocomplete({
|
||||
lookup: [{ value: 'Jamaica', data: 'J' }, { value: 'Jamaica2', data: 'J' }, { value: 'Jamaica3', data: 'J' }],
|
||||
preserveInput: true,
|
||||
onSelect: function (suggestion) {
|
||||
suggestionData = suggestion.data;
|
||||
}
|
||||
});
|
||||
|
||||
input.val('J');
|
||||
instance = input.autocomplete();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
instance.dispose();
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
@ -74,6 +74,7 @@
|
||||
onSearchStart: noop,
|
||||
onSearchComplete: noop,
|
||||
onSearchError: noop,
|
||||
preserveInput: false,
|
||||
containerClass: 'autocomplete-suggestions',
|
||||
tabDisabled: false,
|
||||
dataType: 'text',
|
||||
@ -890,7 +891,9 @@
|
||||
$(that.suggestionsContainer).scrollTop(offsetTop - that.options.maxHeight + heightDelta);
|
||||
}
|
||||
|
||||
that.el.val(that.getValue(that.suggestions[index].value));
|
||||
if (!that.options.preserveInput) {
|
||||
that.el.val(that.getValue(that.suggestions[index].value));
|
||||
}
|
||||
that.signalHint(null);
|
||||
},
|
||||
|
||||
@ -901,7 +904,7 @@
|
||||
|
||||
that.currentValue = that.getValue(suggestion.value);
|
||||
|
||||
if (that.currentValue !== that.el.val()) {
|
||||
if (that.currentValue !== that.el.val() && !that.options.preserveInput) {
|
||||
that.el.val(that.currentValue);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user