Friday, October 22, 2010

jQuery UI autocomplete combobox reloads page when dropdown button is pressed

If you are new to jquery UI, and have used a lot of time trying to figure out autocomplete combobox.
There are some scenarios when you click the dropdown button the page reloads. It only happens when you put your select control inside of a form tag.
To get rid of this problem use the following code.
Add return false at the end of click event.

.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();
        return false;
    });

1 comment: