Skip to content

Commit

Permalink
Autocomplete: Making sure we do not show search menu after a blur. Fi…
Browse files Browse the repository at this point in the history
…xed #7423 - Tab out of autocomplete with remote source can leave menu showing.
  • Loading branch information
spekary authored and scottgonzalez committed Nov 23, 2011
1 parent 54fb144 commit 2445e20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions tests/unit/autocomplete/autocomplete_events.js
Expand Up @@ -157,6 +157,25 @@ asyncTest( "cancel select", function() {
}, 50 );
});

asyncTest( "blur during remote search", function() {
expect( 1 );
var ac = $( "#autocomplete" ).autocomplete({
delay: 0,
source: function( request, response ) {
ok( true, "trigger request" );
ac.simulate( "blur" );
setTimeout(function() {
response([ "result" ]);
start();
}, 100 );
},
open: function() {
ok( false, "opened after a blur" );
}
});
ac.val( "ro" ).keydown();
});

/* TODO previous fix broke more than it fixed, disabling this for now - messed up regular menu select event
test("blur without selection", function() {
expect(1);
Expand Down
4 changes: 3 additions & 1 deletion ui/jquery.ui.autocomplete.js
Expand Up @@ -184,6 +184,7 @@ $.widget( "ui.autocomplete", {
}

clearTimeout( self.searching );
self.cancelSearch = true;
// clicks on the menu (or a button to trigger a search) will cause a blur event
self.closing = setTimeout(function() {
self.close( event );
Expand Down Expand Up @@ -373,6 +374,7 @@ $.widget( "ui.autocomplete", {
_search: function( value ) {
this.pending++;
this.element.addClass( "ui-autocomplete-loading" );
this.cancelSearch = false;

this.source( { term: value }, this.response );
},
Expand All @@ -382,7 +384,7 @@ $.widget( "ui.autocomplete", {
content = this._normalize( content );
}
this._trigger( "response", null, { content: content } );
if ( !this.options.disabled && content && content.length ) {
if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
this._suggest( content );
this._trigger( "open" );
} else {
Expand Down

0 comments on commit 2445e20

Please sign in to comment.