form.py checkbox cannot have a value
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
web.py |
Fix Released
|
Medium
|
Anand Chitipothu |
Bug Description
It seems if you set any value in a checkbox, it renders as checked. So there's no way to have a value and not have it checked. This is troublesome when you want checkboxes of the same name to produce a list of values.
#i.e. I want to do something similar to this:
names = web.select('names')
checkboxes = []
for n in names:
checkboxes.
myform = form.Form(
#in code.py
names = web.input(
I've changed the checkbox class as follows and I hope it or something similar can be committed:
class Checkbox(Input):
def __init__(self, name, *validators, **attrs):
def render(self):
x = '<input name="%s" type="checkbox"' % net.websafe(
if self.value: x += ' value="%s"' % net.websafe(
if self.checked: x += ' checked="checked"'
x += self.addatts()
x += ' />'
return x
Changed in webpy: | |
assignee: | nobody → anandology |
importance: | Undecided → Medium |
status: | New → Confirmed |
Changed in webpy: | |
milestone: | none → 0.33 |
Changed in webpy: | |
status: | Fix Committed → Fix Released |
I just started looking at my code after 8 months, so I am a little rusty, but I think the changes I stated in this bug report break the regular case for a checkbox. So maybe call it a new class -- CheckboxList -- similar to that other bug report for radio buttons.