form.Form.valididates(), fill() and _validate don't affect the "checked" status of Checkbox elements #8

gregglind opened this Issue Mar 29, 2010 · 1 comment

2 participants



from web import form
from web.utils import storify

f = form.Form(
        form.Checkbox('contact_me', checked=True,

f.fill(kw=dict()) # no adding.
assert '''checked="checked"''' in f.render()

f = form.Form(
        form.Checkbox('contact_me', checked=False,
f.fill(kw=dict()) # no adding.
assert '''checked="checked"''' not in f.render()

f.fill(kw=dict(contact_me=True)) # add it.
assert '''checked="checked"''' in f.render(), "didn't fill in"

'fill' is just a shorthand to 'valididates()', which doesn't know how
do much except set the 'value' attribute.

I observe in my tests that indeed, submitted forms don't "stay"
checked. Validators just seem to look at the 'value' attribute, and
that is it. (cf. the _validate method).

The hackish solution is to wire in that "checked means value is valid"
thing yourself. Ugly though!


Looks like the test is wrong.

The fill function expects keyword arguments. So you need to pass values as f.fill(contact_me=True), not as f.fill(kw=...).

When the fill is called with no arguments, the checkbox gets value as None, which means it is not checked.

Here is corrected test and it is working fine.
import web

f = web.form.Form(
    web.form.Checkbox('contact_me', checked=True, description='spam_me')

assert '''checked="checked"''' not in f.render()

assert '''checked="checked"''' in f.render()
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment