Skip to content

Commit 7d8f632

Browse files
author
Dylan Verheul
committed
Fix issue dyve#10 (mustMatch and minChars)
1 parent a744ce2 commit 7d8f632

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# BUILD minified JavaScript
3+
# requires uglifyjs
4+
#
5+
6+
autocomplete:
7+
uglifyjs -nc ./src/jquery.autocomplete.js > ./src/jquery.autocomplete.min.js

demo/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
$(function() {
1313

1414
$("#ac1").autocomplete('search.php', {
15+
minChars: 3,
16+
mustMatch: true,
1517
selectFirst: true
1618
});
1719

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autocomplete",
3-
"version": "3.0.0",
3+
"version": "2.0.0",
44
"title": "jQuery Autocomplete",
55
"author": {
66
"name": "Dylan Verheul",

src/jquery.autocomplete.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,10 @@
494494
$.Autocompleter.prototype.activateNow = function() {
495495
var value = this.beforeUseConverter(this.dom.$elem.val());
496496
if (value !== this.lastProcessedValue_ && value !== this.lastSelectedValue_) {
497+
this.active_ = true;
497498
this.lastProcessedValue_ = value;
498499
if (value.length >= this.options.minChars) {
499500
this.fetchData(value);
500-
} else {
501-
this.finish();
502501
}
503502
}
504503
};
@@ -784,7 +783,6 @@
784783
if (this.autoFill(first, filter) || this.options.selectFirst || (this.options.selectOnly && numResults === 1)) {
785784
this.focusItem($first);
786785
}
787-
this.active_ = true;
788786
};
789787

790788
$.Autocompleter.prototype.showResult = function(value, data) {
@@ -896,11 +894,12 @@
896894
this.callHook('onNoMatch');
897895
}
898896
this.dom.$results.hide();
899-
this.lastKeyPressed_ = null;
900-
this.lastProcessedValue_ = null;
901897
if (this.active_) {
902898
this.callHook('onFinish');
903899
}
900+
this.lastKeyPressed_ = null;
901+
this.lastProcessedValue_ = null;
902+
this.lastSelectedValue_ = null;
904903
this.active_ = false;
905904
};
906905

0 commit comments

Comments
 (0)