views:

33

answers:

1

Hi There,

Im trying to use this JQuery code in my program: http://jqueryui.com/demos/autocomplete/#combobox

Its basically a combo-box which has a auto-complete field and a dropdown button.

When I try to use my combo box inside form tags, it doesnt work properly - the dropdown button keeps submitting the form when i just want to look up values.

Any help appreciated :).

A: 

The original code from the example is the following:

$( "<button>&nbsp;</button>" )
            .attr( "tabIndex", -1 )
            .attr( "title", "Show All Items" )
            .insertAfter( input )
            .button({
                icons: {
                    primary: "ui-icon-triangle-1-s"
                },
                text: false
            })
            .removeClass( "ui-corner-all" )
            .addClass( "ui-corner-right ui-button-icon" )
            .click(function() {
                // close if already visible
                if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
                    input.autocomplete( "close" );
                    return;
                }

                // pass empty string as value to search for, displaying all results
                input.autocomplete( "search", "" );
                input.focus();

            });

I found the solution, just need to make two small changes:

.click(function() {
// close if already visible
if (input.autocomplete("widget").is(":visible")) {
    input.autocomplete("close");
    return false; // CHANGE 1
}
// pass empty string as value to search for, displaying all results
input.autocomplete("search", "");
input.focus();
return false; // CHANGE 2

});

ParampalP