Traker
Traker

Reputation: 2187

Dojo Select widget not selectively querying contents from datastore

I have been trying to use the query functionality of the ItemFileReadStore to filter the list of a select widget's selectable options and it seems that my queries are having no effect on the widget. The query is being done through the onChange event of another select widget, my objective is that when one widget selects a value the other one no longer contains that value as an option). This seemed fairly simple looking at the "Codependent FilteringSelect/ComboBox widgets" example at dojo's docs site. But following this example has left me with no results. My widget that I am trying to use is below:

var sel1 = new dijit.form.Select({
                id:"sel1",
                name: "sel1",
                required: true,
                style: "width: 170px;",
                query: {value: "*" },
                store: selStore
        },"sel1");

I also have another widget sel2 which is similar and uses the same store. My 'onChange' event for both has the following code:

 dojo.connect(element, 'onChange', function(event){
                            dojo.forEach([sel1, sel2], function(element){
                                    if(element.getValue() !== event){
                                            element.attr("query", "{value: !" + event + "}");
                                            console.log("querying", element, element.query);
                                            element.store.fetch();
                                    }
                            });

As a result of this the console printout I get returns the correct element and the element.query is of the form: {value: !val1}, but nothing is being altered in the dropdown of either of the select widgets. If anyone could be of any assistance it would be very much appreciated. Thank you

Upvotes: 0

Views: 1151

Answers (2)

Traker
Traker

Reputation: 2187

After some search and experimentation I have found that dijit.form.Select does not work like the Filtered Select widget when it comes to querying its datastore. In order to query the datastore you must call the setStore method, passing it the same store currently being used and a query object of the form of a fetchArg (i.e. {query: {value: blah}}). See the fetch docs here.

For the second half of the question about finding out how to eliminate options from the store in the effect of fetching all values != value1 you can use a store designed for these types of queries known as the AndOrReadStore which extends from ItemFileReadStore and is compatible with the dijit.form.Select widget, and simply use the NOT keyword.

Upvotes: 0

peller
peller

Reputation: 4543

does the expression !val1 need to be quoted?

Upvotes: 1

Related Questions