#696: NotEmpty validator doesn't work on CheckBoxList
-------------------------------+--------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone:
Component: Widgets | Version: 0.9a1
Severity: normal | Keywords:
-------------------------------+--------------------------------------------
(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:
{{{
#!python
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":
{{{
#!xml
<!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:
{{{
#!python
@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.
--
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/696>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Tickets" 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/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---