Reputation: 123440
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?
Upvotes: 13
Views: 11097
Reputation: 1
I found a easy way:
$("#selectid-selectized").focus(
function () {
$("#selectid")[0].selectize.clear();
})
Upvotes: 0
Reputation: 1
For me $('.someclass input').focus()
did the job. Firstly you choose your selectize element $('.someclass')
, afterwards you choose to select only the input for that element $('.someclass input')
and finally you trigger the focus()
function on the element.
Upvotes: 0
Reputation: 115
$('.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.
Upvotes: 2
Reputation: 128776
One way which appears to work is to call click()
instead of focus()
:
$('.someclass input').click();
Upvotes: 7