Given the following code, the form is displayed properly, but when I
enter a value in the text field, the exception (testing) raised by the
validator is not acted upon. I tried looking tw.forms and formencode
source code, but I am not able to track the problem. Since the
problem seems trivial, it is highly probable that I am not using the
validators or form properly. Would appreciate your input.
Thanks!
controller.py
=========
...
from myforms import InviteForm
class MyClass (CrudRestController):
...
...
new_form = InviteForm('invite_form')
myforms.py
=========
from tw.core import WidgetsList
from tw.forms import TableForm, CalendarDatePicker, TextField
from myvalidators import UserNameValidator
class InviteForm(TableForm):
hover_help = True
class fields (WidgetsList):
invitee_name = TextField(validator=UserNameValidator(),
help_text = 'Please enter a valid user name')
myvalidators.py
============
from formencode import Invalid, FancyValidator
class UserNameValidator(FancyValidator):
messages = {
'usernotfound' : 'User name not found'
}
def _to_python(self, value, string):
if self.strip and isinstance(value, basestring):
value = value.strip()
return value
def validate_python(self, value, state):
self.assert_string(value, state)
# TESTING
if 1:
raise Invalid(self.message('usernotfound', state), value,
state)
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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?hl=en.