[Zope] Using ZPT with options/radio/checkboxes

Paul Winkler pw_lists at slinkp.com
Thu Aug 7 15:17:35 EDT 2003


On Thu, Aug 07, 2003 at 12:54:25PM -0400, Ron Bickers wrote:
> Regardless of the attribute, if the expression evaluates to 'nothing', then
> it's discarded.

yes, i'd missed that... and it's documented.

> One could accomplish the same as above by doing the
> following and there would be no need for special handling of
> checked/selected.
> 
> <input type="checkbox" name="toppings:list" value="Pepperoni"
> tal:attributes="checked python:test('Pepperoni' in path('request/toppings |
> python:[]'), 'checked', nothing)" />
> 
> Not quite as elegant, but it's not horrible and it behaves as expected, yes?

nested python: expressions.... hmm... sorry to say that pushes it
over the "horrible" mark for me :-\

I might write it like this:

<input type="checkbox" name="toppings:list" value="Pepperoni" checked="checked"
 tal:attributes="checked python:test('Pepperoni' in request.get('toppings', []),
                                      default, nothing)" 
/>

or like this:

<input type="checkbox" name="toppings:list" value="Pepperoni" checked="checked"
 tal:attributes="checked python:('Pepperoni' in request.get('toppings',[])) and 
                                default or nothing" />

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's KILLER YELLOW SOLDIER!
(random hero from isometric.spaceninja.com)



More information about the Zope mailing list