Loading multiple select from datasource

I’m trying to use a multiple select in a form. I am able to load the values into a map and set that for the select by calling the fetch on the datasource myself, but just by setting the optionDataSource on the form item itself doesn’t seem to be enough to have it load itself.

Without loading the value map, when the form draws I see what I expect to see in the multiple select, the “selected” values, eg.

2
8

However, when I set the value map, my selections dissapear and I am left with my list with nothing selected.

Apply State Tax
Apply Federal Tax
Apply VAT

(in this case, the Apply State Tax and Apply VAT should be selected per the 2 and 8 values).

If I try to save the selected values prior to setting the value map, and then call select.setValue([2,8]), I end up with a list of

Apply State Tax
Apply Federal Tax
Apply VAT
2
8

with the 2 and 8 lines highlighed. What am I doing wrong? Should the value map not be set by specifying the optionDataSource?

Hi JJohns,

Yes unfortunately multiple selects do not directly support the ‘optionDataSource’ attribute to derive their options from a dataSource - but you’re on the right track with the idea of explicitly calling ‘fetchData()’ on the dataSource and using this to create the valueMap for the form item.

Here’s some sample code that demonstrates this approach:

isc.DynamicForm.create({
    height:200,
    ID:"testForm",
    items:[
        {name:"countries", type:"select", multiple:true}
    ]
});

isc.IButton.create({
    top:210,
    title:"setValue()",
    click:'testForm.setValue("countries", ["UK", "FR"])'
})

isc.DataSource.getDataSource("countryDS").fetchData(
    null, 
    function (response, data) {
        var map = {};
        for (var i = 0; i < data.getLength(); i++) {
            map[data[i].countryCode] = data[i].countryName;
        }
        testForm.getItem("countries").setValueMap(map);
    }
);

You can actually see this in action by copying and pasting into this feature-explorer example in the SDK: JSON DataSource

Let us know if you need further help

Thanks

multiple select fetch

Hi,

To build on this example, I’m attempting to have a multiple select form and then send the values selected to a grid and have the grid show the rows for the specific Keys selected.

For example, select the multiple countries in the form, hit a button and a grid gets updated with the countries population and other information.

Can you please point to an example code that would get me started?

Thanks
Amin

Hi Amin,
As documented here, the criteria property passed to ListGrid.filterData() can be include an array of legal values for some field.
“Multiple select” type items will return their set of selected values as an array.

Therefore you can have a form with a multiple select and call ‘getValues()’ on it, and then pass the values object returned straight into a fetchData() or filterData() call on the grid

var criteria = myForm.getValues();
// criteria may include an array of values for some field
// EG: {idField:[1, 7, 9]}
// Pass this straight to filterData()
myGrid.filterData(criteria);