Ticket #696 (closed defect: fixed)
NotEmpty validator doesn't work on CheckBoxList
|Reported by:||tlesher@…||Owned by:||anonymous|
(version 0.9a2, but that version isn't in Trac yet)
I want to validate that at least one of the checkboxes in a CheckListBox? is selected.
I have this form:
from turbogears import widgets as W from formencode import validators as V task_form = W.TableForm(fields=[W.CheckBoxList(name='tasks', label='Do These:', options=[('spam', 'Eat Spam'), ('eggs', 'Eat Eggs')], validator=V.NotEmpty)], submit_text='Eat')
with this template named "choosetasks.kid":
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'master.kid'"> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/> <title>Choose Tasks</title> </head> <body> <div id="main" py:content="form(action=action)"/> </body> </html>
and with these controller methods:
@turbogears.expose(template='.templates.choosetasks') def choosetasks(self): return dict(form=task_form, action='dotasks') @turbogears.expose() @turbogears.validate(form=task_form) @turbogears.error_handler(choosetasks) def dotasks(self, **data): return '\n'.join('<p>%s:%s</p>' % (k,v) for k,v in data.iteritems())
The goal is to make sure that at least one item is selected (you can eat one or both, but you have to eat something). The validator, though, doesn't seem to be doing its job.
What I see is:
Check "Eat Spam": tasks : [u'spam']
Check "Eat Eggs": tasks : [u'eggs']
Check both: tasks : [u'spam', u'eggs']
Check neither: tasks : 
I'd expect the validator to fire on the last test, but it's not happening.
- Status changed from closed to reopened
- Resolution fixed deleted