Selectize.js: Easy way to set values (for testing purposes)

Created on 29 Apr 2014  路  2Comments  路  Source: selectize/selectize.js

I couldn't find an easy way to write an automatic test for a form using selectize. There's the setTextboxValue but I'm not sure it works completely and it doesn't handle multiple values.

I found a solution (see this SO question) but it would be nice to have a method to set all values at once (or did I miss it?)

question

Most helpful comment

I should have mentioned that I tried that.

Now I realize it works if we add the options first. So in my case it's really:

selectize.addOptions([{text: 'Hello', value: 'Hello'}, {text: 'World', value: 'World'}])
selectize.setValue(['Hello', 'World'])

Works for me, thanks.

All 2 comments

There actually is a setValue method that I think is exactly what you're looking for:

var $select = $('select').selectize();
var selectize = $select[0].selectize;

selectize.setValue('single-value');
selectize.setValue(['multiple','values','work','too']);

There's an example of it here: examples/api.html.

I should have mentioned that I tried that.

Now I realize it works if we add the options first. So in my case it's really:

selectize.addOptions([{text: 'Hello', value: 'Hello'}, {text: 'World', value: 'World'}])
selectize.setValue(['Hello', 'World'])

Works for me, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

themikeb picture themikeb  路  16Comments

ghost picture ghost  路  18Comments

Wardrop picture Wardrop  路  19Comments

jbrooksuk picture jbrooksuk  路  42Comments

AndyBean picture AndyBean  路  15Comments