mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Autocomplete: Trigger search timeout on all input events. Fixes #6666 - keyboard-autorepeat on Firefox and paste event
The input event triggers after all changes to an input field including paste/cut events.
This commit is contained in:
parent
85ac420a1e
commit
adb35572a9
35
ui/jquery.ui.autocomplete.js
vendored
35
ui/jquery.ui.autocomplete.js
vendored
@ -47,7 +47,8 @@ $.widget( "ui.autocomplete", {
|
|||||||
_create: function() {
|
_create: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
doc = this.element[ 0 ].ownerDocument,
|
doc = this.element[ 0 ].ownerDocument,
|
||||||
suppressKeyPress;
|
suppressKeyPress,
|
||||||
|
suppressInput;
|
||||||
|
|
||||||
this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ];
|
this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ];
|
||||||
|
|
||||||
@ -63,10 +64,12 @@ $.widget( "ui.autocomplete", {
|
|||||||
.bind( "keydown.autocomplete", function( event ) {
|
.bind( "keydown.autocomplete", function( event ) {
|
||||||
if ( self.options.disabled || self.element.attr( "readonly" ) ) {
|
if ( self.options.disabled || self.element.attr( "readonly" ) ) {
|
||||||
suppressKeyPress = true;
|
suppressKeyPress = true;
|
||||||
|
suppressInput = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
suppressKeyPress = false;
|
suppressKeyPress = false;
|
||||||
|
suppressInput = false;
|
||||||
var keyCode = $.ui.keyCode;
|
var keyCode = $.ui.keyCode;
|
||||||
switch( event.keyCode ) {
|
switch( event.keyCode ) {
|
||||||
case keyCode.PAGE_UP:
|
case keyCode.PAGE_UP:
|
||||||
@ -110,15 +113,8 @@ $.widget( "ui.autocomplete", {
|
|||||||
self.close( event );
|
self.close( event );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// keypress is triggered before the input value is changed
|
// search timeout should be triggered before the input value is changed
|
||||||
clearTimeout( self.searching );
|
self._searchTimeout( event );
|
||||||
self.searching = setTimeout(function() {
|
|
||||||
// only search if the value has changed
|
|
||||||
if ( self.term != self._value() ) {
|
|
||||||
self.selectedItem = null;
|
|
||||||
self.search( null, event );
|
|
||||||
}
|
|
||||||
}, self.options.delay );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -150,6 +146,14 @@ $.widget( "ui.autocomplete", {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.bind( "input.autocomplete", function(event) {
|
||||||
|
if ( suppressInput ) {
|
||||||
|
suppressInput = false;
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self._searchTimeout( event );
|
||||||
|
})
|
||||||
.bind( "focus.autocomplete", function() {
|
.bind( "focus.autocomplete", function() {
|
||||||
if ( self.options.disabled ) {
|
if ( self.options.disabled ) {
|
||||||
return;
|
return;
|
||||||
@ -317,6 +321,17 @@ $.widget( "ui.autocomplete", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_searchTimeout: function( event ) {
|
||||||
|
var self = this;
|
||||||
|
self.searching = setTimeout(function() {
|
||||||
|
// only search if the value has changed
|
||||||
|
if ( self.term != self.element.val() ) {
|
||||||
|
self.selectedItem = null;
|
||||||
|
self.search( null, event );
|
||||||
|
}
|
||||||
|
}, self.options.delay );
|
||||||
|
},
|
||||||
|
|
||||||
search: function( value, event ) {
|
search: function( value, event ) {
|
||||||
value = value != null ? value : this._value();
|
value = value != null ? value : this._value();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user