[Twisted-web] How to set the selected item in a select box?
Alberto Trujillo
alberto.trujillo at ucd.ie
Wed Jul 20 09:30:48 MDT 2005
I'm trying to fill a simple select box using templates but I have a
problem when I try to set the selected value. Here is my code:
file.py
------------
def render_selectauthor(self, ctx, data):
author = data.firstname + " " + data.lastname
if data.id == self.idauthor:
ctx.fillSlots("authorselected", "selected")
else:
ctx.fillSlots("authorselected", None)
ctx.fillSlots("authorvalue", data.id)
ctx.fillSlots("authorlabel", author)
return ctx.tag
file.html
----------------
<select name="idauthor" nevow:data="selectusers"
nevow:render="sequence">
<option nevow:pattern="item" nevow:render="selectauthor">
<nevow:attr name="value"><nevow:slot name="authorvalue"
/></nevow:attr>
<nevow:attr name="selected"><nevow:slot
name="authorselected" /></nevow:attr>
<nevow:slot name="authorlabel">select...</nevow:slot>
</option>
</select>
The problem is that the attribute selected allways appear in my html
code, and then allways the last item is the selected.
Can anybody tell me how to fix this problem? If possible don't use a
attribute even when I have set this one in my template?
Thank you very much.
More information about the Twisted-web
mailing list