Selectize.js: Documentation is very unclear about how to add options

Created on 21 Mar 2015  路  7Comments  路  Source: selectize/selectize.js

All the documentation says is:

An array of the initial available options. type: array

Naturally, I thought this would be sufficient:

$('#test').selectize({options:['cat','dog','snake']});

However, it turns out I have to do this:

$('#test').selectize({options:[{text:'cat',value:'cat'},{text:'dog',value:'dog'},{text:'snake',value:'snake'}]});

I was only able to figure this out by looking at the definition of "create" in the example on the home page. The documentation should be clearer about the schema of options.

Also, I don't see why it shouldn't accept ['cat','dog','snake'] or even 'cat,dog,snake' with a little introspection, considering it allows things like this in the value field of a text input.

Most helpful comment

Because an issue is not the solution to something so trivial 鈥撀爐his is what pull requests are for. I'm in agreement that it could be improved, and am open to fixes... I just don't have time currently to do it myself and am not open to more actionless +1's. Related: https://github.com/brianreavis/selectize.js/issues/752.

All 7 comments

I second this one. I had to google for an example on Stack Overflow. I had similar issues with other functions in the documentation, such as "setValue(value, silent) Resets the selected items to the given value." - it never specifies that a 'value' is actually the 'value' part of an option pair.

Perhaps it could have a section where it defines all these things.

Open to pull requests.

Hey, why was this closed? What's the resolution on this?

Because an issue is not the solution to something so trivial 鈥撀爐his is what pull requests are for. I'm in agreement that it could be improved, and am open to fixes... I just don't have time currently to do it myself and am not open to more actionless +1's. Related: https://github.com/brianreavis/selectize.js/issues/752.

I agree on both fronts: documentation could be improved, I stumbled upon some sketchy descriptions here and there (and I felt into the trap described above, like many people I guess); and it is the work of contributors to improve it, I think. At least, that's why I forked the project...
(I have myself written recently a comment on an issue telling a trick about placeholder should be documented. Something I should fix myself, I suppose...)

For anyone else that comes across this like me, there is now excellent documentation for Selectize API here: https://github.com/selectize/selectize.js/blob/master/docs/api.md

$('#id').selectize({
create: function(input,callback){
$.ajax({
url: "",
type: "POST",
data: {value : input},
success: function(res) {
callback({value: res, text: input});
}
});
}
});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arathael picture arathael  路  33Comments

ghost picture ghost  路  60Comments

AndyBean picture AndyBean  路  15Comments

ghost picture ghost  路  18Comments

brianreavis picture brianreavis  路  66Comments