Skip to content

Autocomplete: Search if the user retypes the same value #1238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/unit/autocomplete/autocomplete_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,25 @@ test( ".replaceWith() (#9172)", function() {
equal( parent.html().toLowerCase(), replacement );
});

asyncTest( "Search if the user retypes the same value (#7434)", function() {
expect( 3 );
var element = $( "#autocomplete" ).autocomplete({
source: [ "java", "javascript" ],
delay: 0
}),
menu = element.autocomplete( "instance" ).menu.element;

element.val( "j" ).simulate( "keydown" );
setTimeout(function() {
ok( menu.is( ":visible" ), "menu displays initially" );
element.trigger( "blur" );
ok( !menu.is( ":visible" ), "menu hidden after blur" );
element.val( "j" ).simulate( "keydown" );
setTimeout(function() {
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
start();
});
});
});

}( jQuery ) );
9 changes: 7 additions & 2 deletions ui/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,13 @@ $.widget( "ui.autocomplete", {
_searchTimeout: function( event ) {
clearTimeout( this.searching );
this.searching = this._delay(function() {
// only search if the value has changed
if ( this.term !== this._value() ) {

// Search if the value has changed, or if the user retypes the same value (see #7434)
var equalValues = this.term === this._value(),
menuVisible = this.menu.element.is( ":visible" ),
modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;

if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {
this.selectedItem = null;
this.search( null, event );
}
Expand Down