Focusing on a select box (that has selectize enabled) does not focus on the selectized input box:
$('.someclass select').focus();
Focusing on selectize's own inout box doesn't seem to work either:
$('.someclass input').focus();
The Selectize docs mentions focus
but that doesn't seem to work either. See this jsfiddle:
var selectized = $('#selectize').selectize();
selectized.focus();
I would expect the carat |
to be ready and typing to immediately go into the box.
How can I focus on a selectize select box from JavaScript, so a user can type into it?
You should use:
selectized[0].selectize.focus();
One way which appears to work is to call click()
instead of focus()
:
$('.someclass input').click();
$('.someclass input')
returns a jquery object (wrapped set - see What does jquery $ actually return?). You don't want the wrapped set, you want the first element in the set that matches the selector.
Try $('.someclass input')[0].selectize.focus();
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With