Pranav Singh Pranav Singh - 8 months ago 321
Javascript Question

How to clear a selected value selectize.js dropdown

I have a selectize.js dropdown & I have to clear the selected value .

I have tried :

var selectize = $("#optionNetFlow")[0].selectize;

as suggested in an another question How do I set the selectize.js option List programmatically. But it gives an error,

Uncaught TypeError: Cannot read property 'selectize' of undefinedmessage: "Cannot read property 'selectize' of undefined"stack: (...)get stack: function () { [native code] }arguments: nullcaller: nulllength: 0name: ""prototype: StackTraceGetterconstructor: function () { [native code] }__proto__: Object__proto__: function Empty() {}<function scope>set stack: function () { [native code] }__proto__: Error

enter image description here

when I change it to :

var selectize = $("#optionNetFlow").selectize;

I gives error:

TypeError: undefined is not a functionmessage: "undefined is not a function"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Error VM1253:3(anonymous function) VM1253:3InjectedScript._evaluateOn VM1251:732InjectedScript._evaluateAndWrap VM1251:665InjectedScript.evaluate VM1251:579

enter image description here

what I am doing wrong here?


I finally found the answer here Selectize.js Demos

What works for me is:

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

what I was missing var $select = $('#optionNetFlow').selectize(); before applying the solution provided in How do I set the selectize.js option List programmatically.

Now I am to get all the functions in console like :

enter image description here