I've come up with a pretty simple wrapper which does what I want:
<view datapath="@expire">
<combobox id="expireSelector">
<textlistitem text="5 minutes" value="5"/>
<textlistitem text="15 minutes" value="15"/>
<textlistitem text="30 minutes" value="30"/>
</combobox>
<method event="ondata">
expireSelector.selectItem(this.datapath.data);
</method>
</view>
This seems to do the trick. Since I have a handful of these, I would
actually like to build a class to do this, but I'm not sure exactly how to
go about doing this. I've created classes before, but this one sort of
confuses me. What I want is something which is used like this:
<autoSelectingCombobox id="foo" selectionDatapath="@exipre">
<textlistitem text="5 minutes" value="5"/>
<textlistitem text="15 minutes" value="15"/>
<textlistitem text="30 minutes" value="30"/>
</autoSelectingCombobox>
I've tried something like this:
<class name="autoSelectingCombobox" extends="combobox">
<attribute name="selectingDatapath"/>
<datapath name="selectingDatapath">
<method event="ondata">
parent.selectItem(this.data);
</method>
</datapath>
</class>
but when I try to use it, I get an error when I specify the
'selectingDatapath' attribute. Clearly I'm not doing something quite
right.
Any tips on what I'm doing wrong?
Thanks!
On Fri, 31 Mar 2006 14:45:05 -0500, Mike Boutin <[EMAIL PROTECTED]>
wrote:
> Not sure if this will help, but you can have it select like so:
> <combobox>
> <textlistitem datapath="doExtrusions:/extrusions/extrusion/"
> text="$path{'part/text()'}" value="$path{'part/@id'}"
> <method event="ondata">
> <![CDATA[
> if(this.text == YOUR_VALUE_TO_MATCH){
> parent.select(this);
> }
> ]]>
> </method>
> </textlistitem>
> </combobox>
>
> James Howe wrote:
>> I'm trying to use a Combobox in my application. I want the combobox
>> to display a handful of predefined items but I want the currently
>> selected item to be based on a value found in some XML. I have
>> something like this:
>>
>> ...
>> <dataset name="ds">
>> <item value="10"/>
>> <dataset>
>> ...
>>
>> <view datapath="ds:/">
>> <combobox editable="false" datapath="@value">
>> <textlistitem text="5 minutes" value="5"/>
>> <textlistitem text="10 minutes" value="10"/>
>> <textlistitem text="20 minutes" value="20"/>
>> </combobox>
>> </view>
>> ...
>>
>> My idea was that the value of the combobox would be based on the
>> 'value' attribute and when displayed the combobox would display the
>> text '10 minutes'. Unfortunately it doesn't appear to work this way.
>> Instead, I see the text '10' in the combobox.
>>
>> So, my question is simply this, given that I want to display a finite
>> set of items in my combobox, where the text in the combobox is 'human
>> readable', and the value in the XML is an 'internal' value, how do I
>> hook things up so when the data in the XML changes, the combobox will
>> select and display the textlistitem appropriate to the value in the
>> datapath?
>>
>> Thanks!
>>
>>
>>
>
>
--
James Howe
_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user