Cannot Set Combobox Dataprovider When Using Custom Valuelist

Servoy 5.0.1

We use combobox fields as drop-down selection lists. Each combobox has a unique dataprovider and a unique custom valuelist associated with it. Both the dataprovider and custom valuelist are loaded programmatically. For example, here is the (abbreviated) code for loading a list of vendor names:

var dataset = databaseManager.getDataSetByQuery()

var arrayVendorNames = dataset.getColumnAsArray( 1 )

application.setValueListItems( 'vendorlist', arrayVendorNames )

globals.vendorname = 'Select a Vendor'

This produces a combobox as follows:

±-------------------+
| Select a Vendor / |
±-------------------+
| ABC |
| DEF |
| GHI |
| JKL |
±-------------------+

When the ‘Select a Vendor’ combobox is clicked, a list of vendor names drops down. Selecting a vendor name from the drop-down list replaces the ‘Select a Vendor’ with the vendor name, which is also returned in the dataprovider (globals.vendorname). This scenario works fine.

We run into trouble when we have a valuelist that contains a display value and a return value. The (abbreviated) code for that is as follows:

var dataset = databaseManager.getDataSetByQuery()

var arrayVendorNames = dataset.getColumnAsArray( 1 )

var arrayVendorNumber = dataset.getColumnAsArray( 2 )

application.setValueListItems( 'vendorlist', arrayVendorNames, arrayVendorNumber )

globals.vendorname = 'Select a Vendor'

This produces a combobox as follows (NOTE: the dataprovider value is not showing):

±-------------------+
| / |
±-------------------+
| ABC |
| DEF |
| GHI |
| JKL |
±-------------------+

Why is the dataprovider (default) value not being displayed on the combobox when a return value is attached to the drop-down list? Is this a bug? Workarounds?

Thanks!

Hi Kim! :)

I don’t why the difference in behavior, that is more a question for Servoy. But you could change your code to make this work like so:

var dataset = databaseManager.getDataSetByQuery()

var arrayVendorNames = dataset.getColumnAsArray( 1 )

var arrayVendorNumber = dataset.getColumnAsArray( 2 )

application.setValueListItems( 'vendorlist', ["Select a Vendor"].concat(arrayVendorNames), [""].concat(arrayVendorNumber) )

globals.vendorname = ''

This will add the default value to the valuelist with an empy real value. Since the vendorname global stores the real value it also needs to be empty.

Hope this helps.

Kim,

When you use display and real values in a valuelist, Servoy will look for the matching display value of the current dataprovider value.
For example, if your value list is [10, 20, 30], [‘A’, ‘B’, ‘C’] the dropdown will show ‘B’ for dataprovider value 20.

Since there is no mapping for dataprovider ‘Select a value’ in your valuelist, Servoy will leave the value empty…

Robert’s code is a nice workaround for that problem.

Hope this helps,

Rob

Rob and Robert,

Thanks for your responses. I am just getting back to this problem and wanted to make a couple of comments.

Robert…your suggestion of concatenating an item to the value array works just fine. I also found the following to work just as well

arrayVendorNames.push( 'Select a Vendor' )

Rob…

Since there is no mapping for dataprovider ‘Select a value’ in your valuelist, Servoy will leave the value empty…

I take it you mean that the real value is empty. So, why does the display value not show on the combobox as the default? Or, did I make the wrong assumption?