Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open jQuery UI ComboBox on focus

I have a jQuery ComboBox input that when focused I want to automatically open up the autocomplete menu.

However, simply clearing the input and focusing it like this:

$('#select-id').val('').focus();

...doesn't work. If you manually focus an autocompleter input and then clear it, it does display the autocomplete menu.

Is there a way I can trigger the auto complete menu to open on focus? I also would want it to show the complete menu, so I'd want to clear the input text as well.

like image 757
Andy Baird Avatar asked Feb 22 '23 12:02

Andy Baird


1 Answers

Assuming you're using the combobox that's an extension of the autocomplete widget:

$("your_selector").bind("focus", function () {
    this.value = '';
    $(this).autocomplete("search", '');
});

Should work fine.

Working example (normal autocomplete widget): http://jsfiddle.net/gEuTV/

like image 176
Andrew Whitaker Avatar answered Mar 04 '23 05:03

Andrew Whitaker