Select to view content in your preferred language

Unable to dinamically add option to dojo FilteringSelect

1331
3
Jump to solution
08-18-2017 06:08 AM
sitsit
by
New Contributor III

Hi,

I am very new to dojo and I am stuck on this issue. When I try to add a new option, the error "addOption is not a function" arises. This is my code:

Widget.js:

function(
 declare,
 BaseWidget,
 Button,
 _TemplatedMixin,
 _WidgetsInTemplateMixin,
 FilteringSelect,
 on,
 keys,
 Parser,
 Memory,
 array,
 lang,
 map,
 FeatureSet,
 Query,
 QueryTask
 ) {

 return declare([BaseWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {

    name: 'Cerca via', 
    baseClass: 'jimu-widget-CercaVia',
    query: null,
    queryTask: null,

    postCreate: function() {
    console.log("postCreate!");
    var mapFrame = this;
    this.inherited(arguments);
 
    this.ComuniSelect.addOption({disabled:false,label:'label',selected:true,value:1});
 },

Widget.html:

Can someone point me in the right direction?

Bonus question: I would like to add to the FilteringSelect the option to search in the middle of the options. I read that this is possible setting queryExpr to "*$0*". How do I put it into my code?

Thanks,

Marco

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Marco,

I don't normally add an item to my FilteringSelect, I normally clear it and add a new store. Here is what I believe will work:

var myStore = this.ComuniSelect.get('store');
myStore.put({disabled:false,label:'label',selected:true,value:1});
this.ComuniSelect.set('store', myStore);‍‍‍

Bonus question:

this.ComuniSelect.set('queryExpr', '*${0}*');

View solution in original post

0 Kudos
3 Replies
sitsit
by
New Contributor III

I Just discovered that there is not the addOption function for FilteringSelect. So I suppose that I have to work with stores... Can someone show me how to do this?

Thanks,

Marco

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Marco,

I don't normally add an item to my FilteringSelect, I normally clear it and add a new store. Here is what I believe will work:

var myStore = this.ComuniSelect.get('store');
myStore.put({disabled:false,label:'label',selected:true,value:1});
this.ComuniSelect.set('store', myStore);‍‍‍

Bonus question:

this.ComuniSelect.set('queryExpr', '*${0}*');
0 Kudos
sitsit
by
New Contributor III

Thanks, Robert!

The solution you proposed for the bonus question works like a charm.

For the main question I think that I will follow your method: I will clear the FilteringSelect and add a new store. I think it is the best way to accomplish what I want to do.

0 Kudos