On Fri, Dec 18, 2009 at 9:55 AM, W. Martin Borgert <[email protected]> wrote:
> Hi,
>
> sorry for posting again the same issue, but maybe this time
> I get the description of the little problem better.
>
> Hopefully somebody can explain me a change in recent web.py.
> The following code used to work fine in web.py 0.32:
> [...]
> myform = web.form.Form(web.form.Checkbox('A', value=False),
>                        web.form.Checkbox('B', value=True))
> [...]
>
> I.e. the second checkbox was checked by default and the result was
> "on" or None. With web.py 0.33 this code leads to an exception:
>
> Traceback (most recent call last):
>   File "./check33.py", line 11, in <module>
>     web.form.Checkbox('B', value=True))
>   File "/usr/lib/pymodules/python2.5/web/form.py", line 284, in __init__
>     Input.__init__(self, name, *validators, **attrs)
>   File "/usr/lib/pymodules/python2.5/web/form.py", line 124, in __init__
>     self.id = attrs.setdefault('id', self.get_default_id())
>   File "/usr/lib/pymodules/python2.5/web/form.py", line 288, in get_default_id
>     return self.name + '_' + value.replace(' ', '_')
> AttributeError: 'bool' object has no attribute 'replace'
>
> If I change myform in the following way:
>
> myform = web.form.Form(web.form.Checkbox('A', checked=False),
>                        web.form.Checkbox('B', checked=True))
>
> the exception is gone, but the result
> ((form['A'].value, form['B'].value)) is always None, not the
> actual states of the checkboxes.
>
> If I change this line in the following way:
>
> return "Results: %s, %s" % (form['A'].checked, form['B'].checked)
>
> I always get False for the first, True for the second checkbox,
> not the actual states of the checkboxes.
>
> I'm sure I'm missing sth. trivial, but what?

Reported a bug.

https://bugs.launchpad.net/webpy/+bug/498135

I fixed the exception. Try using the latest trunk.

http://github.com/webpy/webpy/commit/43add10136eb503618116b3df683cae23a580c63

Checkboxes are tricky. They have an attribute called value, which is
different from its value.
In 0.32, checkbox.value used to return its value and 0.33 returns the
value of attribute "value" and get_value() returns the actual value
that is the checked status.

Anand

--

You received this message because you are subscribed to the Google Groups 
"web.py" 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/webpy?hl=en.


Reply via email to