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

Implement selection invalidation.

This commit is contained in:
Tomas Kirda 2013-06-07 19:21:24 -05:00
parent a2bea849fc
commit e3e27bb066
2 changed files with 12 additions and 2 deletions

View File

@ -47,6 +47,9 @@ $(function () {
}, },
onHint: function (hint) { onHint: function (hint) {
$('#autocomplete-ajax-x').val(hint); $('#autocomplete-ajax-x').val(hint);
},
onInvalidateSelection: function() {
$('#selction-ajax').html('You selected: none');
} }
}); });

View File

@ -100,6 +100,7 @@
}; };
that.hint = null; that.hint = null;
that.hintValue = ''; that.hintValue = '';
that.selection = null;
// Initialize and set options: // Initialize and set options:
that.initialize(); that.initialize();
@ -178,6 +179,7 @@
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.fixPosition(); });
that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); });
}, },
onBlur: function () { onBlur: function () {
@ -347,11 +349,10 @@
return; return;
} }
that.findBestHint();
clearInterval(that.onChangeInterval); clearInterval(that.onChangeInterval);
if (that.currentValue !== that.el.val()) { if (that.currentValue !== that.el.val()) {
that.findBestHint();
if (that.options.deferRequestBy > 0) { if (that.options.deferRequestBy > 0) {
// Defer lookup in case when value changes very quickly: // Defer lookup in case when value changes very quickly:
that.onChangeInterval = setInterval(function () { that.onChangeInterval = setInterval(function () {
@ -367,6 +368,11 @@
var that = this, var that = this,
q; q;
if (that.selection) {
that.selection = null;
(that.options.onInvalidateSelection || $.noop)();
}
clearInterval(that.onChangeInterval); clearInterval(that.onChangeInterval);
that.currentValue = that.el.val(); that.currentValue = that.el.val();
@ -654,6 +660,7 @@
that.el.val(that.currentValue); that.el.val(that.currentValue);
that.signalHint(null); that.signalHint(null);
that.suggestions = []; that.suggestions = [];
that.selection = suggestion;
if ($.isFunction(onSelectCallback)) { if ($.isFunction(onSelectCallback)) {
onSelectCallback.call(that.element, suggestion); onSelectCallback.call(that.element, suggestion);