2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-12-23 03:18:55 +00:00

Merge branch 'master' of github.com:devbridge/jQuery-Autocomplete

Conflicts:
	src/jquery.autocomplete.js
This commit is contained in:
Tomas Kirda 2013-01-15 12:37:42 -06:00
commit ffa963663a
3 changed files with 53 additions and 1 deletions

View File

@ -32,6 +32,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
* `noCache`: Boolean value indicating whether to cache suggestion results. Default `true`.
* `onSearchStart`: `function (query) {}` called before ajax request. `this` is bound to input element.
* `onSearchComplete`: `function (query) {}` called after ajax response is processed. `this` is bound to input element.
* `tabDisabled`: Default `false`. Set to true to leave the cursor in the input field after the user tabs to select a suggestion.
##Usage

View File

@ -137,4 +137,54 @@ describe('Autocomplete', function () {
expect(completeQuery).toBe('A');
});
});
it('Should should not preventDefault when tabDisabled is set to false', function () {
var input = document.createElement('input'),
autocomplete = new $.Autocomplete(input, {
lookup: [{ value: 'Jamaica', data: 'B' }],
tabDisabled: false});
input.value = 'Jam';
autocomplete.onValueChange();
var event = $.Event('keydown');
event.keyCode = 9; // the tab keycode
spyOn(event, 'stopImmediatePropagation');
spyOn(event, 'preventDefault');
spyOn(autocomplete, 'suggest');
expect(autocomplete.visible).toBe(true);
expect(autocomplete.disabled).toBe(undefined);
expect(autocomplete.selectedIndex).not.toBe(-1);
$(input).trigger(event);
expect(event.stopImmediatePropagation).not.toHaveBeenCalled();
expect(event.preventDefault).not.toHaveBeenCalled();
expect(autocomplete.suggest).not.toHaveBeenCalled();
});
it('Should should preventDefault when tabDisabled is set to true', function () {
var input = document.createElement('input'),
autocomplete = new $.Autocomplete(input, {
lookup: [{ value: 'Jamaica', data: 'B' }],
tabDisabled: true});
input.value = 'Jam';
autocomplete.onValueChange();
var event = $.Event('keydown');
event.keyCode = 9; // the tab keycode
spyOn(event, 'stopImmediatePropagation');
spyOn(event, 'preventDefault');
spyOn(autocomplete, 'suggest');
expect(autocomplete.visible).toBe(true);
expect(autocomplete.disabled).toBe(undefined);
expect(autocomplete.selectedIndex).not.toBe(-1);
$(input).trigger(event);
expect(event.stopImmediatePropagation).toHaveBeenCalled();
expect(event.preventDefault).toHaveBeenCalled();
expect(autocomplete.suggest).not.toHaveBeenCalled();
});
});

View File

@ -87,6 +87,7 @@
onSearchStart: noop,
onSearchComplete: noop,
containerClass: 'autocomplete-suggestions',
tabDisabled: false,
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
}
@ -275,7 +276,7 @@
return;
}
that.select(that.selectedIndex);
if (e.keyCode === keys.TAB) {
if (e.keyCode === keys.TAB && this.options.tabDisabled === false) {
return;
}
break;