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

Closed
gregglind opened this Issue Mar 29, 2010 · 1 comment

2 participants

@gregglind

Cf: http://groups.google.com/group/webpy/browse_thread/thread/ea49983d0d839fa6?pli=1

from web import form
from web.utils import storify

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

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

f = form.Form(
        form.Checkbox('contact_me', checked=False,
description='spam_me')
)
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
to
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!

@anandology

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')
)

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

f.fill(contact_me=True) 
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