Welcome, guest ( Login )

WikiHome » DojoDataUseCases » Binding Data Values to a Widget

Binding Data Values to a Widget

Version 12, changed by chrism 02/20/2007.   Show version history




Summary:  

A data value in a DataStore can be used to assign the value of a property in a particular widget.   For example, assigning the default value of an input text field from a value in a list of data in the DataStore.

Scenario

User provides ISBN number in input field, and presses Submit button.  Submit triggers a find on an XML data store, which results in the title of the book being stored in the title text box.

Programmatic:

var store = new dojox.data.XMLStore("/books");
var args = {
oncompleted: function(r) {}, // no place holder
};
...
var button1 = dojo.byId("Button1");
var text2 = dojo.byId("Text2"); // an input text box

var results = null;
dojo.event.connect(button1, "onclick", function() {
results = store.find(args);
});

dojox.data.bind(
{scope: args, event: "oncompleted"},
{datastore: store, object: results.item[0], path: "title/text()"}, // Automatically knows how to deal with XML or JS
{object: text2, property: "value"});


Declarative


Note:
the syntax used here is for the purposes of fleshing out the api, and is not proper dojo declarative markup.

<!-- View -->
ISBN: <Textbox widgetId="Textbox1" />
<Button widgetId="Button1" caption="Submit"/>
Title: <Textbox widgetId="Textbox2" disabled="disabled" />

<!-- Model -->
<DataSet widgetId="Args1" />
<XmlStore widgetId="Store1" url="/bookStore" />
<DataSet widgetId="Result1" />

<!-- Controller -->
<Binding trigger="Textbox1.onblur" source="Textbox1.value" target="Args1.data.query.isbn" />
<Action trigger="Button1.onclick" method="Store1.find" params="Args1.data" result="Result1.data" />
<Binding trigger="Args1.oncompleted" source="Result1.data.items[0]/title/text()" target="Textbox2.value" />
<Action trigger="Args1.onerror" method="alert" />


Discussion:







Attachment (1)

  File By Size Attached Ver.
 data-to-widget.jpg jaredj 6K 02/16/2007 2 Delete attachment