repopulate the combo box

I have two combo boxes, each one associated with a data source. The second combo box will depend on the first combo box. On the change for the first combo box, I get the new data(because of the new fetch criteria) for the second combo box, but how to repopulate the 2nd combo box? The example in the smartClient website for select dependency does not work for this case, because the data is hard coded in that example.

I came up a way to get the new data sent back from the client, but I don’t know how to repopulate the 2nd combo box using the data. The following is the sample code:

actually, When selection changes on the first select box, I need to just provide new filter
criteria for the second select box without changing the datasource.

{name: “Combo1”,
title: “Combo 1”,
editorType: “comboBox”,
showOptionsFromDataSource: true,
optionDataSource: “combo1DS”,
valueField: “Id”,
displayField: “Name”,
change: function(form, item, value, oldValue) {
combo2DS.fetchData({Id: value}, function(data, rpcResponse, rpcRequest) {
//How to repopulate the Combo2 using the data??
});
return true;
}
},
{name: “Combo2”, ID: “Combo2”,
title: “Combo 2”,
editorType: “comboBox”,
showOptionsFromDataSource: true,
optionDataSource: “combo2DS”,
pickListWidth: 200,
valueField: “Id”,
displayField: “Name”},

Hi peihua -

The way to do this is to specify a getPickListFilterCriteria() on the second databound select box that automatically computes the appropriate criteria, then provide a change() handler on the first select box that calls clearValue() on the second combo box. So e.g, for your case:

{
  name: "Combo1",
  title: "Combo 1",
  editorType: "comboBox",
  showOptionsFromDataSource: true,
  optionDataSource: "combo1DS",
  valueField: "Id",
  displayField: "Name",
  change: "form.clearValue('Combo2')"
},
{
  name: "Combo2", ID: "Combo2",
  title: "Combo 2",
  editorType: "comboBox",
  showOptionsFromDataSource: true,
  optionDataSource: "combo2DS",
  pickListWidth: 200,
  valueField: "Id",
  displayField: "Name",
  getPickListFilterCriteria: function () {
    // return criteria based on the selection of Combo1 (or whatever else)
    var combo1Value = formID.getValue('Combo1');
  
    return {foo: combo1Value};  // 
  }
}

So whenever the user changes Combo1, Combo2 will be reset and then when the user pulls down Combo2, it’ll automatically fetch data with the criteria returned by getPickListFilterCriteria(). Does this work for you?

form.clearValue() is not a function

Thanks for your reply. I tried and it said that form.clearValue(‘Combo2’) is not a function. Of course, I replace the form to my formID.

My bad - that should be:

form.getField('Combo2').clearValue()

Sorry for the confusion.

Hi, I tried this piece of code in my program, because I also need a filtered combo box, but unfortunately it doesn’t work.

In my example both combo boxes use the same datasource. The first combo box shows postcodes and the second shows city-names. So when I pick a postcode the second combo box should only show the cities with the proper postcode.
But when I open the second combo box it shows all cities.

Interesting
If you’re overriding ‘getPickListFilterCriteria()’ we would expect this to work
Could you post the code for the Form containing the 2 comboBoxItems so we can take a look?

Thanks

Here is my code:

isc.DynamicForm.create({
	ID: "Form1",
	left: 9, top: 20,
	fields : [{
		name: "Combo1",
		title: "Combo 1",
		editorType: "comboBox",
		showOptionsFromDataSource: true,
		optionDataSource: "plz",
		valueField: "PLZ",
		displayField: "PLZ",
		change: "Form2.getField('Combo2').clearValue()"
	}]
})



isc.DynamicForm.create({
	ID: "Form2",
	left: 9, top: 60,
	fields : [{
		name: "Combo2", 
		title: "Combo 2",
		editorType: "comboBox",
		showOptionsFromDataSource: true,
		optionDataSource: "plz",
		pickListWidth: 200,
		valueField: "PLZ",
		displayField: "ORT",
		getPickListFilterCriteria: function () {
 			var combo1Value = Form1.getValue('Combo1');
 			return {foo: combo1Value};   
		}
	}]
})

Hi Arne - I just tried your example and it basically worked for me.
However I noticed that you use “foo” as your fieldName in the generated criteria - is this a valid field-name from your dataSource?

If not I would expect this not to work if you’re using our built in SQL layer, as the server will be performing the filter based on the values for fields in the dataSouce only - other entries will essentially be ignored. Try changing to the fieldName of a field from your dataSouce (which sounds like what you’ll be doing for the “real” application) and see if that fixes the problem.

If not let us know and we’ll take a deeper look
Thanks
Isomorphic Software

Yes, that was the fault. Thank you very much for the hint. Now it works great! :slight_smile:

Arne

populating combobox based on row details in a listgrid

Hi,
We have a similar requirement in a list grid. My code for the comboBox

getPickListFilterCriteria: function() {
// id = myForm.getValue(‘id’);
//here i need to access the record
}
I am not able to access the record object there(which will be used to set the criteria).
How to access the record items in the function…

Hey Arne, I am working on something very similar to your code. Can you tell me when you initially load a page with two combos and a first combo has a value selected is the second combo’s selection filtered on the value from the first one?

Thanks

If you want to get the currently selected record on the ListGrid, you can use the getSelectedRecord() method. More generally, you can access the records in a ListGrid using the data property, then use List methods to get the specific record(s) you want.

How to get the listgrid object inside getPickListFilterCriteria

Hi
we are using datasource xml,
Inside the function we are not able to get listgrid object, in order to call getSelectedRecord()
How to get the listgrid object inside the function?

for the comboBox

<field name="test" title="Test Combo" type="comboBox" 
	width="160"	optionDataSource="comboTest" displayField="id" 
	valueField="someValue" defaultValue="None" showHover="true" >
        <getPickListFilterCriteria>
               <JS>
                        function() {
                                //here i need to access the record 
                                 
                        }
               </JS>
        </getPickListFilterCriteria>
   </field>

You can use the ID of the ListGrid to reference it from within the getPickListFilterCriteria method.

If your DataSource is going to be used in other applications, it’s probably better to put this method in your DynamicForm field definition instead of the DataSource itself so it would just be used for that DynamicForm.

You should be able to use a combination for listGrid.getEditedRow() and listGrid.getEditedRecord() (passing the result of the first call to the second to get the edited record). Does that work for you?