My current method is to loop through the data in the controller and
convert it to a dictionary:
[code]
cat_select = []
cats = list(NewsCat.select())
for cat in cats:
cat_option = {'value': cat.id, 'content': cat.name}
if cat.id == article.category.id:
cat_option['selected'] = True
else:
cat_option['selected'] = None
cat_select.append(cat_option)
[/code]
Then, in my .kid I have the following:
[code]
<option py:for="cat in categories" value="${cat['value']}"
py:content="cat['content']" py:attrs="selected=cat['selected']">
An Option
</option>
[/code]
That way, when kid evaluates cat['selected'], if it's none the
SELECTED attribute is simply dumped.
Lee
On 27/10/05, Kevin Dangoor <[EMAIL PROTECTED]> wrote:
>
> My current solution (which I'll freely admit is less-than-ideal) is this:
>
> <select name="foo">
> <option value="A" py:attrs="selected=std.selector(foo=='A')">A</option>
> <option value="B" py:attrs="selected=std.selector(foo=='B')">B</option>
> </select>
>
> Kevin
>
> On 10/27/05, william <[EMAIL PROTECTED]> wrote:
> >
> > How can I report easily the value of a <select> form object ?
> >
> > Imagine I have a select with 5 <options> (A,B,C,D,E) and the recorded
> > value is C.
> > What's the best method to put the famous selected="selected" in the
> > <option> corresponding to "C" ?
> >
> > - generating it in the controller the whole list of <options> (as a
> > string) ?
> > - making a loop in Kid ?
> > - ????
> >
> > Personnally I don't like the 2 first possibilities, and I'll appreciate
> > a 3rd.
> >
> > Thanks
> >
> >
>
>
> --
> Kevin Dangoor
> Author of the Zesty News RSS newsreader
>
> email: [EMAIL PROTECTED]
> company: http://www.BlazingThings.com
> blog: http://www.BlueSkyOnMars.com
>