[ZPT] select, option, selected in ZPT?

Godefroid Chapelle gotcha@swing.be
Wed, 19 Jun 2002 16:26:52 +0200


At 15:55 19/06/2002, you wrote:
>Hi Folks
>
>I'm trying to figure out how to retain form data after a post (in the 
>event of an error of some sort) so I fill in the values of the form with 
>what was passed. For example, a registration process that must do a DB 
>query and return the same form if the username is already taken so the 
>user can pick another without filling out the whole thing again.
>
>How would I add the "selected" attribute to an <option> html tag in zpt? 
>Does the tal:attribute method work? If so, wouldn't I need to tell it what 
>attribute to assign a value to?
>
>Basically I want to do this in pseudocode
>while (dropdown)
>if dropdown[n] == options.dropdown_from_post:
>     <option "selected">Blah</option>
>else:
>     <option>Blah not selected</option>
>
>Thanks
>


This could help you :


ZPT

<select name="usernames:list" tal:define="emptylist python:[];
                                           usernames 
python:here.getUsernames();
                                           selectedones request/usernames | 
emptylist">
  <option tal:repeat="username usernames"
                 tal:attributes="selected python:username in selectedones"
                 tal:content="python:username">displayname</option>

</select>

BTW, second item of a google search "zpt selected option".

>-jim

--

Godefroid Chapelle

BubbleNet sprl
rue Victor Horta, 18 / 202
1348 Louvain-la-Neuve
Belgium

Tel + 32 (10) 459901
Mob + 32 (477) 363942

TVA 467 093 008
RC Niv 49849