How can I focus on the selectize select field?

Focusing on the selection field (with selection turned on) does not focus on the selected input field:

$('.someclass select').focus(); 

Focusing on choosing your own inout window doesn't work either:

 $('.someclass input').focus(); 

Selectize docs mentions focus , but that doesn't work either. See jsfiddle :

 var selectized = $('#selectize').selectize(); selectized.focus(); 

I would expect a carat | will be ready and typing to immediately enter the box.

How can I focus on the select select box from JavaScript so the user can enter it?

+6
source share
4 answers

You should use:

 selectized[0].selectize.focus(); 
+17
source

One way that works is to call click() instead of focus() :

 $('.someclass input').click(); 
+5
source

$('.someclass input') returns a jquery object (wrapped set - see What does jquery $ return? ). You do not want the wrapped set, you want the first element in the set to match the selector.

Try $('.someclass input')[0].selectize.focus(); .

+2
source

For me, $('.someclass input').focus() did the job. First, you select the select element $('.someclass') , after which you select only the input for this element $('.someclass input') and, finally, you call the focus() function on the element.

0
source

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


All Articles