]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Combobox demo - Collapse menu when clicking button.
authorScott González <scott.gonzalez@gmail.com>
Thu, 13 Dec 2012 21:55:14 +0000 (16:55 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 13 Dec 2012 21:55:14 +0000 (16:55 -0500)
demos/autocomplete/combobox.html

index 6229d47b2167b9e2170e317519a6981c18d780cc..38c75e157f114ad0231fa193c80ee7cafa11ebde 100644 (file)
@@ -39,6 +39,7 @@
                        _create: function() {
                                var input,
                                        that = this,
+                                       wasOpen = false,
                                        select = this.element.hide(),
                                        selected = select.children( ":selected" ),
                                        value = selected.val() ? selected.text() : "",
                                        })
                                        .removeClass( "ui-corner-all" )
                                        .addClass( "ui-corner-right ui-combobox-toggle" )
+                                       .mousedown(function() {
+                                               wasOpen = input.autocomplete( "widget" ).is( ":visible" );
+                                       })
                                        .click(function() {
+                                               input.focus();
+
                                                // close if already visible
-                                               if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
-                                                       input.autocomplete( "close" );
-                                                       removeIfInvalid( input );
+                                               if ( wasOpen ) {
                                                        return;
                                                }
 
-                                               // work around a bug (likely same cause as #5265)
-                                               $( this ).blur();
-
                                                // pass empty string as value to search for, displaying all results
                                                input.autocomplete( "search", "" );
-                                               input.focus();
                                        });
 
                                input.tooltip({