mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-09 23:01:00 +00:00
Merge branch 'master' of github.com:devbridge/jQuery-Autocomplete
Conflicts: src/jquery.autocomplete.js
This commit is contained in:
commit
ffa963663a
@ -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`.
|
* `noCache`: Boolean value indicating whether to cache suggestion results. Default `true`.
|
||||||
* `onSearchStart`: `function (query) {}` called before ajax request. `this` is bound to input element.
|
* `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.
|
* `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
|
##Usage
|
||||||
|
|
||||||
|
@ -137,4 +137,54 @@ describe('Autocomplete', function () {
|
|||||||
expect(completeQuery).toBe('A');
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
@ -87,6 +87,7 @@
|
|||||||
onSearchStart: noop,
|
onSearchStart: noop,
|
||||||
onSearchComplete: noop,
|
onSearchComplete: noop,
|
||||||
containerClass: 'autocomplete-suggestions',
|
containerClass: 'autocomplete-suggestions',
|
||||||
|
tabDisabled: false,
|
||||||
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
||||||
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
||||||
}
|
}
|
||||||
@ -275,7 +276,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
that.select(that.selectedIndex);
|
that.select(that.selectedIndex);
|
||||||
if (e.keyCode === keys.TAB) {
|
if (e.keyCode === keys.TAB && this.options.tabDisabled === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user