mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-25 22:27:39 +00:00
Implement selection invalidation.
This commit is contained in:
parent
a2bea849fc
commit
e3e27bb066
@ -47,6 +47,9 @@ $(function () {
|
||||
},
|
||||
onHint: function (hint) {
|
||||
$('#autocomplete-ajax-x').val(hint);
|
||||
},
|
||||
onInvalidateSelection: function() {
|
||||
$('#selction-ajax').html('You selected: none');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -100,6 +100,7 @@
|
||||
};
|
||||
that.hint = null;
|
||||
that.hintValue = '';
|
||||
that.selection = null;
|
||||
|
||||
// Initialize and set options:
|
||||
that.initialize();
|
||||
@ -178,6 +179,7 @@
|
||||
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('change.autocomplete', function (e) { that.onKeyUp(e); });
|
||||
},
|
||||
|
||||
onBlur: function () {
|
||||
@ -347,11 +349,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
that.findBestHint();
|
||||
|
||||
clearInterval(that.onChangeInterval);
|
||||
|
||||
if (that.currentValue !== that.el.val()) {
|
||||
that.findBestHint();
|
||||
if (that.options.deferRequestBy > 0) {
|
||||
// Defer lookup in case when value changes very quickly:
|
||||
that.onChangeInterval = setInterval(function () {
|
||||
@ -367,6 +368,11 @@
|
||||
var that = this,
|
||||
q;
|
||||
|
||||
if (that.selection) {
|
||||
that.selection = null;
|
||||
(that.options.onInvalidateSelection || $.noop)();
|
||||
}
|
||||
|
||||
clearInterval(that.onChangeInterval);
|
||||
that.currentValue = that.el.val();
|
||||
|
||||
@ -654,6 +660,7 @@
|
||||
that.el.val(that.currentValue);
|
||||
that.signalHint(null);
|
||||
that.suggestions = [];
|
||||
that.selection = suggestion;
|
||||
|
||||
if ($.isFunction(onSelectCallback)) {
|
||||
onSelectCallback.call(that.element, suggestion);
|
||||
|
Loading…
Reference in New Issue
Block a user