Hi,
I have checkbox group (checkboxes with same name) in my form
categoryForm = form.Form(
#other form elements here
form.Checkbox('categories', value='cat1'),
form.Checkbox('categories', value='cat2'),
form.Checkbox('categories', value='cat3'),)
and handle it in class like this
data = web.input(categories=[])
frmCategory = categoryForm()if not frmCategory.validates(data):
return frmCategory.render()
I have checked checkboxes' values as list and send them form's validate
function as source data but it fails when it checks checkbox's validation.
The problem is Checkbox class's set_value() function. It sets checked
property with bool(value). In this situation value is a list which has
checked checkboxes' values but not unchecked ones. However it renders as
checked also unchecked checkboxes after (failed)validation. I built this[1]
patch to handle this. How do you handle this?
[1]:
*** form.py 2010-03-20 19:40:06.000000000 +0200--- form_modified.py
2011-03-17 10:10:01.198136668 +0200****************** 301,307 ****
return '<input %s/>' % attrs
def set_value(self, value):! self.checked = bool(value)
def get_value(self):
return self.checked--- 301,313 ----
return '<input %s/>' % attrs
def set_value(self, value):! if isinstance(value, list):!
if self.value in value:! self.checked = True!
else:! self.checked = False! else:!
self.checked = bool(value)
def get_value(self):
return self.checked
--
Aydın Şen
--
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.