Multiple checkboxes value and one stacktrace error

29 views
Skip to first unread message

SeC

unread,
Sep 8, 2009, 4:41:02 AM9/8/09
to web.py
Hi.
I noticed that form.Checkbox cannot have value, it's always 'on', so
is there any other to create multiple checkboxes with the same name
and diffrent values? Right now I'm using something like this:
l = []
for i in my_list:
l.append(form.Checkbox('x_' % i.id))
form = form.Form(*l)

and then after POST I iterate and if input name starts with 'x_' I
parse that ID etc.
I found this bug report - https://bugs.launchpad.net/webpy/+bug/128233
- but it's old and left untouched.
Any suggestions? Also sometimes when I have error in my code I only
get last stacktrace in web browser and I have to check console for
full stacktrace - anyone else got this?

Anand Chitipothu

unread,
Sep 8, 2009, 10:34:25 AM9/8/09
to we...@googlegroups.com
2009/9/8 SeC <sec...@gmail.com>:

>
> Hi.
> I noticed that form.Checkbox cannot have value, it's always 'on', so
> is there any other to create multiple checkboxes with the same name
> and diffrent values? Right now I'm using something like this:
> l = []
> for i in my_list:
>  l.append(form.Checkbox('x_' % i.id))
> form = form.Form(*l)
>
> and then after POST I iterate and if input name starts with 'x_' I
> parse that ID etc.
> I found this bug report - https://bugs.launchpad.net/webpy/+bug/128233
> - but it's old and left untouched.

Fixed now.

SeC

unread,
Sep 9, 2009, 4:51:57 AM9/9/09
to web.py
>>> web.form.Checkbox('checkbox1', value = 'test').render()
'<input type="checkbox" id="checkbox1" name="checkbox1"/>'

Still no 'value' attribute.

On 8 Wrz, 16:34, Anand Chitipothu <anandol...@gmail.com> wrote:
> 2009/9/8 SeC <sec....@gmail.com>:
>
>
>
> > Hi.
> > I noticed that form.Checkbox cannot have value, it's always 'on', so
> > is there any other to create multiple checkboxes with the same name
> > and diffrent values? Right now I'm using something like this:
> > l = []
> > for i in my_list:
> >  l.append(form.Checkbox('x_' % i.id))
> > form = form.Form(*l)
>
> > and then after POST I iterate and if input name starts with 'x_' I
> > parse that ID etc.
> > I found this bug report -https://bugs.launchpad.net/webpy/+bug/128233

Anand Chitipothu

unread,
Sep 9, 2009, 4:57:15 AM9/9/09
to we...@googlegroups.com
2009/9/9 SeC <sec...@gmail.com>:

>
>>>> web.form.Checkbox('checkbox1', value = 'test').render()
> '<input type="checkbox" id="checkbox1" name="checkbox1"/>'
>
> Still no 'value' attribute.

Sorry, that was a mistake. Fixed now.

andrei

unread,
Sep 13, 2009, 1:21:39 PM9/13/09
to web.py
I would expect this to work:


all_name_values = [1,2,3,4,5]

checkboxes = []
for i in all_name_values:
checkboxes.append(form.Checkbox('names', value=i))
my_form = form.Form(*checkboxes)


my_values = web.input(names=[])
form_with_values = my_form(my_values)

And when calling form_with_values.render() I expect to see all
checkboxes with value in my_values to be checked.
I also would expect form_with_values.names and
form_with_values.d.names to return arrays.


On Sep 9, 12:57 pm, Anand Chitipothu <anandol...@gmail.com> wrote:
> 2009/9/9 SeC <sec....@gmail.com>:

andrei

unread,
Sep 13, 2009, 1:54:21 PM9/13/09
to web.py
And creating Checkbox without value doesn't work now.

andrei

unread,
Sep 13, 2009, 2:39:25 PM9/13/09
to web.py
I consider Checkbox implementation is broken now, because

1. I can't create Checkbox without value like this:

from web import form
item_form = form.Form(form.Checkbox("chk"))


2. If I create form this way and try to validate it against the data
that has no value for the Checkbox:

from web import form
item_form = form.Form(form.Checkbox("chk", value="on"))
if item_form.validates(dict(abs="rr")):
print item_form.d

<Storage {'chk': "on"}>

Then item_form.d still has the value for "chk", but in case of
inserting item_form.d in database, it needs to be None if the Checkbox
wasn't checked. Well, it worked for me in the version before I did:

from web import form
item_form = form.Form(form.Checkbox("chk"))
if item_form.validates(dict(abs="rr")):
print item_form.d

<Storage {'chk': None}>

Anand Chitipothu

unread,
Sep 13, 2009, 11:11:20 PM9/13/09
to we...@googlegroups.com
2009/9/14 andrei <andr...@gmail.com>:

>
> I consider Checkbox implementation is broken now, because
>
> 1. I can't create Checkbox without value like this:
>
>  from web import form
>  item_form =  form.Form(form.Checkbox("chk"))
>
>
> 2. If I create form this way and try to validate it against the data
> that has no value for the Checkbox:
>
>  from web import form
>  item_form =  form.Form(form.Checkbox("chk", value="on"))
>  if item_form.validates(dict(abs="rr")):
>      print item_form.d
>
> <Storage {'chk': "on"}>
>
> Then item_form.d still has the value for "chk", but in case of
> inserting item_form.d in database, it needs to be None if the Checkbox
> wasn't checked. Well, it worked for me in the version before I did:
>
> from web import form
> item_form =  form.Form(form.Checkbox("chk"))
> if item_form.validates(dict(abs="rr")):
>    print item_form.d
>
> <Storage {'chk': None}>

Try now. Fixed both.

http://github.com/webpy/webpy/commit/e8fe53871d3f5ee99213178e563ee09773ec0e5a

Anand

Tupteq

unread,
Oct 1, 2009, 12:25:35 PM10/1/09
to web.py
On Sep 14, 5:11 am, Anand Chitipothu <anandol...@gmail.com> wrote:
> Try now. Fixed both.

I checked this code and I can't validate specific form with it:

import web.form
form = web.form.Form(
web.form.Checkbox('chk', checked=True))
form.validates({'chk':None})
print form.d.chk

It always prints True, value put to validates() is not important.
Reply all
Reply to author
Forward
0 new messages