[ZPT] option selected?

Clemens Robbenhaar robbenhaar at espresto.com
Mon Jan 5 14:49:59 EST 2004


cccurvey writes:
 > Ack!  I'm both confused and off-topic!  I'm trying to make sure that
 > the select box that's in the form reflects the state of the record
 > that was retrieved from the database (and I'm using the SimpleTAL
 > package from owlfish.com to do this outside of Zope).  
 > 
 >     Category:
 >     <select name="categoryId">
 >         <option tal:repeat="category categoryList"
 > 	        tal:attributes="selected 
 >                     python:category['categoryId']==case.categoryId; 
 >                     value category/categoryId"
 > 		tal:content="category/categoryName">
 >         </option>
 >     </select>
 > 
 > This all works well and gives me something like
 > 
 > <select name="categoryId">
 >     <option value="1" selected="false">Foo</option>
 >     <option value="2" selected="true">Bar</option>
 >     <option value="3" selected="false">Snafu</option>
 > </select>

I do not have simpleTAL running locally, but I guess something like

<option tal:repeat="category categoryList"
  tal:attributes="selected 
                  python:(category['categoryId']==case.categoryId) and 'selected' or nothing; 
                  value category/categoryId"
 	tal:content="category/categoryName">


 may do the job. However this depends on if SimpleTAL does not render
attributes with a value on "nothing". If You are out of luck, You will
get something like:

      <option value="1" selected="None">Foo</option>

instead of

      <option value="1">Foo</option>
 
(which is the behaviour of the TALES specification, if I have readi the
spec right)


In case SimpleTAL does not follow the spec You may need to render the
complete tag by a python format string or the like :-/.

Cheers,
Clemens



More information about the ZPT mailing list