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
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('');
});
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