If one uses a WidgetsList?, and assigns a validator to a field widget, the error message that should be displayed when a validation fails, is not displayed. Validation does appear to work as the CSS classes for the fields that failed validation are modified.
a very basic piece of code placed in root.py in a new virtual environment with TG 2.0.1
I didn't see any documentation on this, but, Form doesn't display the label_text. I am not sure if this is intentional or not.
from tw.core import WidgetsList
from tw.forms import Form, ListForm, TableForm, TextField, TextArea, RadioButton
List, CheckBox, HiddenField, SingleSelectField, PasswordField
from tw.forms.validators import NotEmpty, Regex, Email
from pylons import c
from tg import redirect, validate, flash, request
class TestForm(TableForm):
action = 'testadd'
submit_text = 'Add test'
class fields(WidgetsList): #User = TextField()
User = TextField(label_text='FTP Username', size=40, validator=NotEmpty())
#User = TextField(label_text='FTP Username', size=40, validator=Email())
...
@expose('tg201.templates.template')
def form(self, **kw):
c.form = TestForm()
return dict(template='test',value=None)
@validate(TestForm(), error_handler=form)
def testadd(self, **kw):
flash('great success')
redirect('form')
template
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
${tmpl_context.form(value=value)}
</div>
If I install tw.forms-0.9.2.tar.gz or tw.forms-0.9.3dev-20090405.tar.gz, validation error messages are displayed.