5

My goal is to reset selected values in selectize input. I called selectize function in seperate js file (working with Ruby on Rails), so there is no option to create some global selectize input variable (at least I want to avoid it).

In select2 I would solve similar issue like that:

$(".select2").select2("val", "")

but when I call selectize() second time on the input all previous options and collection loaded via ajax just dissappear.

Thanks for help

1 Answer 1

4

Selectize uses .selectized as its identifying class.

Unfortunately, selectize is not accessible via $('.selectized').selectize - you need to go directly to the <select>/<input> element - $('.selectized')[0].selectize as shown in the docs.

I don't believe you can access all selectize items at once, you need to iterate through them. I recommend using the map function, such as something like:

$.map($('.selectized'), function(item, index) { 
  item.selectize.setValue('');
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Works but in my case I had to call it with selectize()[0] $('.selectized').first().selectize()[0].selectize.setValue('')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.