[Zope] TALs difficulties
Jim Penny
jpenny at universal-fasteners.com
Wed Sep 1 10:21:37 EDT 2004
On Wed, 01 Sep 2004 14:45:19 +0200
Johan Carlsson <johanc at easypublisher.com> wrote:
>
> Hi,
> I need help :-)
>
> I'm trying to implement a new Widget for Archetypes.
> So I have to write TAL (not my favorite hobby).
>
>
> Here's what I've settled for so far:
> vocab is the DisplayList derivative (item is a key).
>
> <tal:loop repeat="item vocab">
> <optgroup
> tal:attributes="label python:vocab.getValue(item);"
> tal:condition="python:vocab.isLabel(item)">
> </optgroup>
> <option selected=""
> tal:condition="not:python:vocab.isLabel(item)"
> tal:attributes="value item;
> selected python:test(here.unicodeTestIn(item, value),
>
> 'selected', None);"
> tal:content="python: vocab.getValue(item)"/>
> </tal:loop>
This is a simple neting mistake, try:
<tal:loop repeat="item vocab">
<optgroup
tal:attributes="label python:vocab.getValue(item);"
tal:condition="python:vocab.isLabel(item)">
<option selected=""
tal:condition="not:python:vocab.isLabel(item)"
tal:attributes="value item;
selected python:test(here.unicodeTestIn(item, value),
' selected', None);"
tal:content="python: vocab.getValue(item)"/>
</optgroup>
</tal:loop>
Though, as a matter of taste, I don't like this approach, I suspect that
it will be hard to maintain, as it depends on whatever is generating
vocab to deliver values in a sorted order. To me it would be much more
natural to use a nested loop paramterized on the label value to generate
the options.
>
> Returns something like this:
>
> <optgroup label="A"></optgroup>
> <option>Ada</option>
> <option>Ape</option>
> <optgroup label="B"></optgroup>
> <option>Bananas</option>
> <option>Buffy</option>
>
> What I want is:
>
> <optgroup label="A">
> <option>Ada</option>
> <option>Ape</option>
> </optgroup>
> <optgroup label="B">
> <option>Bananas</option>
> <option>Buffy</option>
> </optgroup>
>
> Which renders quite differently.
>
> Best Regards,
> Johan
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
>
More information about the Zope
mailing list