Open jQuery UI ComboBox in focus

I have a jQuery ComboBox input, which when I focus, I want to automatically open the autocomplete menu.

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

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

... does not work. If you manually configure the autocomplete input and then clear it, it will display the autocomplete menu.

Is there a way by which I can start an automatic full menu to open in focus? I would also like it to display the full menu, so I would also like to clear the input text.

+4
source share
2 answers

Assuming you are using combobox that the autocomplete widget extension is:

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

Should work fine.

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

+8
source

If you need this functionality for every instance of jqueryui combobox, and not just for a specific selector, you can put it inside $ (widget ("custom-combobox", {statement (good place for it above or below _createShowAllButton)

 _showAll: function() var input = this.input, wasOpen = false; $(input) .focus(function() { wasOpen = input.autocomplete("widget").is(":visible"); }); .click(function() { input.focus(); // this fires the call above. // Close if already visible if (wasOpen) { return; } input.autocomplete("search", ""); }); }, 

This simply repeats the functionality of the show all button, launching it when focusing. This makes it unnecessary to create a separate binding for each operator and will work with each drop-down list.

0
source

Source: https://habr.com/ru/post/1379420/


All Articles