On Mon, Feb 9, 2009 at 4:59 AM, Damian <[email protected]> wrote:
>
> Hi,
>
> Been banging my head against this for a bit - the following code in
> mako:
>    <%
>      selectvals = {'U':'Not specified','M':'Male','F':'Female'}
>    %>
>     ${selectvals[c.Gender]}
>     - change to:
>      ${h.select('gender', c.Gender, selectvals.items())}
>
> (where c.Gender is set to 'F' for example) quite happily displays
> Female - change to: and then the select box, but with no default!  I
> cannot seem to get it to work - it works fine if integers are used,
> but refuses when a string is used.  The Html output is:
>
>  Female - change to:
> <select name="gender">
> <option value="M">Male</option>
> <option value="U">Not specified</option>
> <option value="F">Female</option>
> </select>
>
> using WebHelpers 0.6.3.
>
> am I missing something? Thanks.

The second argument should be the value ('U').  You're probably
passing the prompt instead ('Not specified').


$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from webhelpers.html import tags
>>> selectvals = {'U':'Not specified','M':'Male','F':'Female'}
>>> print tags.select('gender', 'U', selectvals.items())
<select id="gender" name="gender">
<option value="M">Male</option>
<option selected="selected" value="U">Not specified</option>
<option value="F">Female</option>
</select>
>>> print tags.select('gender', 'Not specified', selectvals.items())
<select id="gender" name="gender">
<option value="M">Male</option>
<option value="U">Not specified</option>
<option value="F">Female</option>
</select>
>>>

Hint: by using a list of pairs rather than a dict, you can control the
order of the prompts.

-- 
Mike Orr <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to