]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Search if the user retypes the same value 1238/head
authorTJ VanToll <tj.vantoll@gmail.com>
Thu, 1 May 2014 13:57:38 +0000 (09:57 -0400)
committerTJ VanToll <tj.vantoll@gmail.com>
Mon, 12 May 2014 17:37:13 +0000 (13:37 -0400)
Fixes #7434
Closes gh-1238

tests/unit/autocomplete/autocomplete_core.js
ui/autocomplete.js

index 2a901006bcf0bd2a467115d8b729853ef5efdd9d..c306495f20cf0cacd08b96fa133ef568504b3d76 100644 (file)
@@ -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 ) );
index 10de5dc19945a713f803c4ae5193393f0ff7defc..d53a1d5e3553f146f70b5d9a7580daba8c83527c 100644 (file)
@@ -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 );
                        }