]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Making sure we do not show search menu after a blur. Fixed #7423 -...
authorShannon <spekary@gmail.com>
Wed, 23 Nov 2011 18:39:45 +0000 (13:39 -0500)
committerScott González <scott.gonzalez@gmail.com>
Wed, 23 Nov 2011 18:39:45 +0000 (13:39 -0500)
tests/unit/autocomplete/autocomplete_events.js
ui/jquery.ui.autocomplete.js

index 286d902f1f8077a7c754c3ce3e7ce33016dbae0e..d6a008ea2cbf2c2b5dae63395aebb258bd047580 100644 (file)
@@ -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);
index 9871b52d773c7716e2feccadd4bee11456513896..dbda2058ed89cdf9d47d8832fba082a8b7bb03d9 100644 (file)
@@ -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 );
@@ -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 );
        },
@@ -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 {