Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the selectize.js options list programmatically?

Tags:

selectize.js

I know how to set the optionList on Initiliaztion but how do I set it programmatically?

I have an inviteList array:

$("#select-invite").options(inviteList); 
like image 631
sly_Chandan Avatar asked Dec 10 '13 15:12

sly_Chandan


People also ask

How do I add options in Selectize?

You can add options like this: var $select = $(document. getElementById('mySelect')). selectize(options); var selectize = $select[0].

How do I remove Selectize?

Remove the option select[0]. selectize. removeItem(selectedValue); select[0].


1 Answers

You can use load method to set options via programmatic API. You may also want to call clear and clearOptions methods to reset selected values and old options.

Here is how to put it all together:

var selectize = $("#select-invite")[0].selectize; selectize.clear(); selectize.clearOptions(); selectize.load(function(callback) {     callback(inviteList); }); 

Please note that inviteList should be an array of objects that have properties configured in valueField and labelField options when select was initialized. For example, here is how inviteList should look like with default valueField and labelField options:

var inviteList = [     {         text: 'Option One',         value: 1     },     {         text: 'Option Two',         value: 2     } ]; 
like image 150
byte255 Avatar answered Sep 24 '22 01:09

byte255