2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-29 00:06:36 +00:00

Enable support for minChars: 0. Fixes #95.

This commit is contained in:
Tomas Kirda 2013-08-31 16:16:00 -05:00
parent 2f260cec63
commit 1906d93ff9
2 changed files with 15 additions and 5 deletions

View File

@ -56,6 +56,7 @@ $(function () {
// Initialize autocomplete with local lookup: // Initialize autocomplete with local lookup:
$('#autocomplete').autocomplete({ $('#autocomplete').autocomplete({
lookup: countriesArray, lookup: countriesArray,
minChars: 0,
onSelect: function (suggestion) { onSelect: function (suggestion) {
$('#selection').html('You selected: ' + suggestion.value + ', ' + suggestion.data); $('#selection').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
} }

View File

@ -179,10 +179,18 @@
that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); }); that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); });
that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); }); that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); });
that.el.on('blur.autocomplete', function () { that.onBlur(); }); that.el.on('blur.autocomplete', function () { that.onBlur(); });
that.el.on('focus.autocomplete', function () { that.fixPosition(); }); that.el.on('focus.autocomplete', function () { that.onFocus(); });
that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); }); that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); });
}, },
onFocus: function () {
var that = this;
that.fixPosition();
if (that.options.minChars <= that.el.val().length) {
that.onValueChange();
}
},
onBlur: function () { onBlur: function () {
this.enableKillerFn(); this.enableKillerFn();
}, },
@ -259,7 +267,7 @@
that.intervalId = window.setInterval(function () { that.intervalId = window.setInterval(function () {
that.hide(); that.hide();
that.stopKillSuggestions(); that.stopKillSuggestions();
}, 300); }, 50);
}, },
stopKillSuggestions: function () { stopKillSuggestions: function () {
@ -430,15 +438,16 @@
if ($.isFunction(options.serviceUrl)) { if ($.isFunction(options.serviceUrl)) {
serviceUrl = options.serviceUrl.call(that.element, q); serviceUrl = options.serviceUrl.call(that.element, q);
} }
if(this.currentRequest != null) { if (that.currentRequest) {
this.currentRequest.abort(); that.currentRequest.abort();
} }
this.currentRequest = $.ajax({ that.currentRequest = $.ajax({
url: serviceUrl, url: serviceUrl,
data: options.ignoreParams ? null : options.params, data: options.ignoreParams ? null : options.params,
type: options.type, type: options.type,
dataType: options.dataType dataType: options.dataType
}).done(function (data) { }).done(function (data) {
that.currentRequest = null;
that.processResponse(data, q); that.processResponse(data, q);
options.onSearchComplete.call(that.element, q); options.onSearchComplete.call(that.element, q);
}); });