I'm trying to find a way to set a default value in selectize.js.
I know that in jQuery you can use:
$(".country").val("US");
But this doesnt work with Selectize. I already read the API documentation and I tried using:
$(".country").selectize().setValue("US");
But it doesnt work either.
I'm a newbie so I'm probably missing something here but can't figure out what. Any ideas?
Per the documentation, API functions are called on the selectize property that the selectize() call adds to the original select or input element; this property points to the underlying selectize instance.
Since it's a property of the element, you use the [0] syntax to the element from jQuery:
// initialize the selectize control
var $select = $('.country').selectize();
$select[0].selectize.setValue("US");
maybe items can be used..
$('select').selectize({
items : [""], // initializing selected value to nothing
plugins: ['remove_button','restore_on_backspace']
});
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