Skip to content

Commit 48001a8

Browse files
committed
Autocomplete: Search if the user retypes the same value
Fixes #7434 Closes jquerygh-1238
1 parent 5bbf276 commit 48001a8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tests/unit/autocomplete/autocomplete_core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,25 @@ test( ".replaceWith() (#9172)", function() {
338338
equal( parent.html().toLowerCase(), replacement );
339339
});
340340

341+
asyncTest( "Search if the user retypes the same value (#7434)", function() {
342+
expect( 3 );
343+
var element = $( "#autocomplete" ).autocomplete({
344+
source: [ "java", "javascript" ],
345+
delay: 0
346+
}),
347+
menu = element.autocomplete( "instance" ).menu.element;
348+
349+
element.val( "j" ).simulate( "keydown" );
350+
setTimeout(function() {
351+
ok( menu.is( ":visible" ), "menu displays initially" );
352+
element.trigger( "blur" );
353+
ok( !menu.is( ":visible" ), "menu hidden after blur" );
354+
element.val( "j" ).simulate( "keydown" );
355+
setTimeout(function() {
356+
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
357+
start();
358+
});
359+
});
360+
});
361+
341362
}( jQuery ) );

ui/autocomplete.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,13 @@ $.widget( "ui.autocomplete", {
394394
_searchTimeout: function( event ) {
395395
clearTimeout( this.searching );
396396
this.searching = this._delay(function() {
397-
// only search if the value has changed
398-
if ( this.term !== this._value() ) {
397+
398+
// Search if the value has changed, or if the user retypes the same value (see #7434)
399+
var equalValues = this.term === this._value(),
400+
menuVisible = this.menu.element.is( ":visible" ),
401+
modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
402+
403+
if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {
399404
this.selectedItem = null;
400405
this.search( null, event );
401406
}

0 commit comments

Comments
 (0)