3

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.

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();

            });

Any help appreciated :).

0

1 Answer 1

4

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
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.