2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-25 14:17:45 +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:
$('#autocomplete').autocomplete({
lookup: countriesArray,
minChars: 0,
onSelect: function (suggestion) {
$('#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('keyup.autocomplete', function (e) { that.onKeyUp(e); });
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); });
},
onFocus: function () {
var that = this;
that.fixPosition();
if (that.options.minChars <= that.el.val().length) {
that.onValueChange();
}
},
onBlur: function () {
this.enableKillerFn();
},
@ -259,7 +267,7 @@
that.intervalId = window.setInterval(function () {
that.hide();
that.stopKillSuggestions();
}, 300);
}, 50);
},
stopKillSuggestions: function () {
@ -430,15 +438,16 @@
if ($.isFunction(options.serviceUrl)) {
serviceUrl = options.serviceUrl.call(that.element, q);
}
if(this.currentRequest != null) {
this.currentRequest.abort();
if (that.currentRequest) {
that.currentRequest.abort();
}
this.currentRequest = $.ajax({
that.currentRequest = $.ajax({
url: serviceUrl,
data: options.ignoreParams ? null : options.params,
type: options.type,
dataType: options.dataType
}).done(function (data) {
that.currentRequest = null;
that.processResponse(data, q);
options.onSearchComplete.call(that.element, q);
});