tags:

views:

497

answers:

2

Hi!

I am trying to code two filteringselects which should both change according to data entered into any of the forms.

So data entered into fs1 should trigger changes in fs2. Data entered into fs2 should trigger changes in fs1.

I am in a spring environment which in my case means that the dojo code is in a jsp file and the filtering select fields are populated through a Controller class on the server side using @ModelAttribute annotations to make the data available as a variable in the jsp file.

I have the relation data on the Java side so it's available through the controller.

Here is what confuses me at the moment.

  1. I am new to DOJO and the documentation on the DOJO support site is a little hard to grasp for me. I would like to see a conceptual list of what is needed to accopmplish and connect the separate stores of my filteringselects.

  2. When there is a change in one of the filteringselects, how do I inform the controllerclass of the changes and send the data that remains in the filteringselect?

This question could also be read as: how can I call a method with input parameters that hold the data available in the edited filteringselect?

+1  A: 

I suggest we work on this in two incremental parts:

  1. Get the first FilteringSelect's onChange event working
  2. Wire them up to use server data stores

The following code sample takes a Dojo Campus' codependent FilteringSelect example and simplifies it so that its data stores are local. It shows how to programmatically instantiate two FilteringSelects with the second being dependent on the first by an onChange event handler.

Can you please try running it and let me know if you get it working?

Once we get your first FilteringSelect triggering filtering on the second, I will edit to add an explanation on how to convert them to use server side data stores.

<html>
<head>
<title>Test File</title>
<link type="text/css" rel="stylesheet" href="dijit/themes/tundra/tundra.css"/>
</head>
<body class="tundra">

<label for="state">State:</label>
<input id="state">

<label for="city">City:</label>
<input id="city">

<script type="text/javascript" src="dojo/dojo.js"
        djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");

    dojo.addOnLoad(function() {
        var cityJson = {
            label: 'name',
            items: [{ name: 'Albany', state: 'NY' },
                    { name: 'New York City', state: 'NY' },
                    { name: 'Buffalo', state: 'NY' },
                    { name: 'Austin', state: 'TX' },
                    { name: 'Houston', state: 'TX' }]
            };
        var stateJson = {
            identifier: 'abbreviation',
            label: 'name',
            items: [ { name: 'New York', abbreviation: 'NY' },
                     { name: 'Texas', abbreviation: 'TX' } ]
            };

        new dijit.form.ComboBox({
            store: new dojo.data.ItemFileReadStore({
                data: cityJson
            }),
            autoComplete: true,
            query: {
                state: "*"
            },
            style: "width: 150px;",
            required: true,
            id: "city",
            onChange: function(city) {
                dijit.byId('state').attr('value', (dijit.byId('city').item || {
                    state: ''
                }).state);
            }
        },
        "city");

        new dijit.form.FilteringSelect({
            store: new dojo.data.ItemFileReadStore({
                data: stateJson
            }),
            autoComplete: true,
            style: "width: 150px;",
            id: "state",
            onChange: function(state) {
                dijit.byId('city').query.state = state || "*";
            }
        },
        "state");
    });
</script>

</body>
</html>
Abboq
A: 

Thank you Abboq.

Unfortunately I got delayed about a month because there were other prioritizations in the project, but now I'm back at this.

I tried your example and it works excellently. Now to figure out how to load the data dynamically.

There is one other issue as well. Loading the datastore on pageload is not an option for me as the datastores would then hold close to 10 000 values.

I need to start with empty or maybe just a partial list and then fill the datastore as the first character is entered.

Kalle