combobox in pylons

4 views
Skip to first unread message

gazza

unread,
Jan 2, 2010, 11:40:34 AM1/2/10
to pylons-discuss
Hello,

I want to use a combo box in my template. I can use the standard html
approach however I would like
to use the pylons helper functions to accomplish this.

In my controller,I have the following:

c.credcardtypes=[("visa","visa")]

the template has:

${h.select("fieldnm","initvalue",c.credcardtypes)}

I dont know how to add multiple values to the combo list?

Much appreciated,
Garyc

gazza

unread,
Jan 2, 2010, 12:01:51 PM1/2/10
to pylons-discuss
Hello,

Ok I think I figured it out:

class creditcardtype(BaseController):
def __init__(self,name,value,parent=None):
self.name=name
self.value=value


def registration(self):
self.cclist.append(creditcardtype("visa","visa"))
self.cclist.append(creditcardtype
("americanexpress","americanexpress"))
c.creditcardtypes=[(ct.name,ct.value) for ct in self.cclist]

That basically does what I want to do, however is there a better way
than this?

Much appreciated,
Garyc

Paweł Stradomski

unread,
Jan 3, 2010, 7:10:39 PM1/3/10
to pylons-...@googlegroups.com
W liście gazza z dnia sobota 02 stycznia 2010:

> Hello,
>
> Ok I think I figured it out:
>
> class creditcardtype(BaseController):
> def __init__(self,name,value,parent=None):
> self.name=name
> self.value=value
>
>
> def registration(self):
> self.cclist.append(creditcardtype("visa","visa"))
> self.cclist.append(creditcardtype
> ("americanexpress","americanexpress"))
> c.creditcardtypes=[(ct.name,ct.value) for ct in self.cclist]
>
> That basically does what I want to do, however is there a better way
> than this?

Why not this way:
c.creditcardtypes=[("visa","visa"), ("americanexpress","americanexpress")]

Also, why does creaditcardtype derive from BaseController?

--
Paweł Stradomski

gazza

unread,
Jan 8, 2010, 3:56:24 PM1/8/10
to pylons-discuss

Ahh, but of course. Thanks for the tip.

gazza

unread,
Jan 8, 2010, 3:58:18 PM1/8/10
to pylons-discuss
Yep it doesnt have to be derived from BaseController, a cut and paste
error.

On Jan 3, 7:10 pm, Paweł Stradomski <pstradom...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages