PDA

View Full Version : defaule text in combobox


thriputapriya
07-20-2004, 07:47 AM
HI Antun,

How can i change the default text in second combobox dynamically when i select an item in the first combobox?

I mean, in the below code, when i select the item "asia" from the first combobox and select the item "india" from the second combox,and again select the Europe, the second combobox still show the item "india" instead of showing one of the item under an item "Europe" in the first combobox.


<canvas width="800" height="800" debug="true">
<dataset name="countriesContinents">
<item value="asia" >Asia
<item value="india">India</item>
<item value="japan">Japan</item>
</item>
<item value="europe" >Europe
<item value="italy">Italy</item>
<item value="france">France</item>
</item>
<item value="northAmerica" >North America
<item value="italy">Canada</item>
<item value="france">USA</item>
<item value="france">Mexico</item>
</item>
</dataset>

<combobox x="5" y="5"
width="130"
shownitems="3"
editable="false"
defaulttext="choose one...">
<textlistitem datapath="countriesContinents:/item"
text="$path{'text()'}"
value="$path{'@value'}"/>
<method event="onselect">
Debug.write( "onselect called" );
var dp = "countriesContinents:/item[@value='" + this.value
+ "']";
Debug.write( dp );
countries.setDataPath( dp );
</method>
</combobox>



<combobox name="countries"
datapath=""
x="5" y="30"
width="130"
editable="false"
shownitems="3"
defaulttext="choose one..." >
<textlistitem datapath="item" text="$path{'text()'}"
value="$path{'@value'}"/>
</combobox>

</canvas>

antun
07-20-2004, 10:28 AM
After you call setDatapath, what happens is that the views that make up the replicated <textlistitem> instances get instantiated. This is asynchronous, so although it's fairly easy to write a selectFirstItem method for <combobox>, it's no use calling it immediately following countries.setDatapath in the first combobox, because those views are not fully instantiated at that point.

Instead, the thing to do is to add some code to the second combobox, so that whenever its <textlistitem>s finish replicating, it selects the first item:


<combobox name="countries"
datapath=""
x="5" y="30"
width="130"
editable="false"
shownitems="3"
defaulttext="choose one..." >
<textlistitem text="$path{'text()'}"
value="$path{'@value'}">
<datapath xpath="item">
<method event="onclones" name="fooMethod">
var last = clones[ clones.length - 1 ];
if ( !last.isinited ){
var d = new LzDelegate( this, "replicationDone" );
d.register( last , "oninit" );
}
</method>
<method name="replicationDone">
Debug.write( 'replication done!' );
this.parent.selectFirstItem();
</method>
</datapath>
</textlistitem>
<method name="selectFirstItem">
var firstItemVal = datapath.xpathQuery("item[1]/@value");
this.selectItem(firstItemVal);
</method>
</combobox>


-Antun