Bind controls

I know we can bind listgrids and trees to xml data. What about other controls like text fields, listboxes, radiobuttons?

Thanks

The valueMap for a SelectItem or ComboBox can be bound to a DataSource via the optionDataSource property. Examples are online:

http://www.smartclient.com/#listComboBox
http://www.smartclient.com/#_Forms_Data.Types_List.-.Related.Records

Any other type of form control can be populated with XML-derived data by calling DataSource.fetchData() and populating a form with the resulting data via form.setValues().

<Any other type of form control can be populated with XML-derived data by calling DataSource.fetchData() and populating a form with the resulting data via form.setValues().

Is there a sample of this in the docs?

No, but here’s a sample:

    [i]myDataSource[/i].fetchData(null, "[i]myForm[/i].setValues(data[0])");

Where myDataSource and myForm are instances of DataSource and DynamicForm respectively. “data” in the callback fired from fetchData is an Array of Objects - this populates the form as a whole with the first one.

Let me see if I understand it correctly. I am setting up a datasource and assign it to be a datasource for a dynamic form. At the end of my JS code I issue myDataSource.fetchData(null, “myForm.setValues(data[0])”); to populate all controls in myForm?

Yes. The other way to get DataSource-derived data into a DynamicForm is to call myForm.editSelectedData(myListGrid) if you have already loaded records into a ListGrid and you want to edit the selected record.

Alright, but how it’s known what data from derived XML goes to what control? What I am missing is how do I assign datafld to a specific control (text box for example)? I see how I am creating fields for the dynamic form but I am not sure about how I am assigning data to a field.

The value of a given dataSource field goes to the form field of the same name.

I see.
Here is a code fragment:
<code>
isc.DataSource.create({
ID:“countryDS”,
dataFormat:“xml”,
dataURL:“accidents.asp?methodexecute=mtest&datarequest=xml”,
recordXPath:“//country”,
fields:[
{name:“countryCode”, title:“Code”},
{name:“countryName”, title:“Country”},
{name:“independence”, title:“Nationhood”, type:“date”},
{name:“population”, title:“Population”, type:“integer”},
{name:“gdp”, title:“GDP”, type:“float”}
]
});

isc.DynamicForm.create({
ID:“frmGeneral”,
dataSource: countryDS,
numCols: “4”,
border:“1px solid blue”, padding:5,
colWidths: [“15%”, “10%”, “10%”, “*”],
fields:[
{name: “countryName”, title: “countryName”, type: “text”},
</code>
I am trying to create a field “countryName”. I would expect that that field will be showing first node’s data for that field. But it (field) comes blank.
What am I doing wrong?

In this code fragment, there is so far no call to fetchData(). As previously mentioned in this thread, a call like the following would populate a DynamicForm with the first node in the returned data:

    [i]myDataSource[/i].fetchData(null, "[i]myForm[/i].setValues(data[0])");