mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-12-22 19:08:55 +00:00
Merge branch 'onhide-callback-option' of https://github.com/stffndtz/jQuery-Autocomplete into stffndtz-onhide-callback-option
Conflicts: dist/jquery.autocomplete.js dist/jquery.autocomplete.min.js readme.md spec/autocompleteBehavior.js src/jquery.autocomplete.js
This commit is contained in:
commit
a2c472853b
@ -53,6 +53,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
|
||||
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`.
|
||||
* `onHide`: `function (container) {}` called before container will be hidden
|
||||
|
||||
Autocomplete instance has following methods:
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*jslint vars: true*/
|
||||
/*jslint vars: true*/
|
||||
/*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $, beforeEach*/
|
||||
|
||||
describe('Autocomplete Async', function () {
|
||||
@ -703,6 +703,32 @@ describe('Autocomplete', function () {
|
||||
expect(suggestionsContainer.find('.autocomplete-no-suggestion').text()).toBe('Sorry, no matching results');
|
||||
});
|
||||
|
||||
it('Should call onHide and pass container jQuery object', function () {
|
||||
var element = document.createElement('input'),
|
||||
input = $(element),
|
||||
instance,
|
||||
elementCount,
|
||||
context;
|
||||
|
||||
input.autocomplete({
|
||||
lookup: [{ value: 'Jamaica', data: 'B' }],
|
||||
onHide: function (container) {
|
||||
context = this;
|
||||
elementCount = container.length;
|
||||
}
|
||||
});
|
||||
|
||||
input.val('Jam');
|
||||
instance = input.autocomplete();
|
||||
instance.onValueChange();
|
||||
|
||||
input.val('Colombia');
|
||||
instance.onValueChange();
|
||||
|
||||
expect(context).toBe(element);
|
||||
expect(elementCount).toBe(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('When options.preserveInput is true', function () {
|
||||
|
@ -612,7 +612,14 @@
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
var that = this;
|
||||
var that = this,
|
||||
container = $(that.suggestionsContainer);
|
||||
|
||||
if ($.isFunction(this.options.onHide) && that.visible) {
|
||||
|
||||
this.options.onHide.call(that.element, container);
|
||||
}
|
||||
|
||||
that.visible = false;
|
||||
that.selectedIndex = -1;
|
||||
clearInterval(that.onChangeInterval);
|
||||
@ -622,6 +629,7 @@
|
||||
|
||||
suggest: function () {
|
||||
if (this.suggestions.length === 0) {
|
||||
this.options.showNoSuggestionNotice ? this.noSuggestions() : this.hide();
|
||||
if (this.options.showNoSuggestionNotice) {
|
||||
this.noSuggestions();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user