Question

I tried removing all options from dijit.form.filteringselect and adding an option to dijit.form.filteringselect using the below function. However, I am getting an error: no method getOptions and addOption. am using dojo 1.7

function showTablesDropDown(tableDiv){
  dijit.byId(tableDiv).removeOption(dijit.byId(tableDiv).getOptions());
  dijit.byId(tableDiv).addOption(dojo.create("option", {label:"None", value:"None"}));
}

How to remove all options from dijit.form.filteringselect and add option to dijit.form.filteringselect?

Was it helpful?

Solution

The problem here is just a slight misunderstanding of how the FilteringSelect (and anything that inherits from _AutoCompleterMixin) interacts with its data. Regardless of how you are creating the FilteringSelect widget, the underlying mechanism for controlling its options is an object that adheres to the Dojo Store API.

This means that in order to modify your FilteringSelect widget's options, you need to interact with this store instead. I've set up this fiddle to demonstrate, but basically you want to change your function to something like:

function showTablesDropDown(tableDiv){
   var filteringSelectWidget = dijit.byId(tableDiv);

   // Clear current value since options are changing.
   filteringSelectWidget.set("value", ""); 

   var store = filteringSelectWidget.get("store");
   var newData = [{label: "None", value: "None"}];    

   // Give the underlying store a new data array.
   store.setData(newData);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top