FieldsMatch validation

15 views
Skip to first unread message

Jens.Hof...@gmail.com

unread,
Jul 17, 2008, 5:21:10 PM7/17/08
to ToscaWidgets-discuss
Hello all,

First thanks to Alberto for pointing me to group, so I will be just
bothering you instead of the pylons world ;)

A few words about myself: I'm an experienced python and web
programmer, with more than 5 years experience in Python, and
web......well, I don't really want to count those :) I have created
web applications in a lot of different, common (and not-so-common)
languages, but there are still things to learn.

My biggest web project with Python was a bigger site building on top
of pure Myghty, but when I got now a request for a new project, I
decided to give pylons a try, and after asking which way to build
forms best, I got pointed to ToscaWidgets and tw.forms, so, here I am.

I have created my first form successfully already, and it is working
so far, the only thing I can't get to run even after an hour of
reading docs and googling, is the FieldsMatch validator (for a user
registration form, of course)

Here is the code for the widget:

--- snip ---

from tw import forms
from tw.api import WidgetsList
import tw.forms.validators as v
forms.FormField.engine_name = "mako"


class RegisterForm(forms.ListForm):
class fields(WidgetsList):
username = forms.TextField(validator = v.All( v.MinLength(5),
v.MaxLength(32), v.UnicodeString(not_empty = True), v.PlainText()))
givenname = forms.TextField()
surname = forms.TextField()
email = forms.TextField(validator = v.Email(not_empty = True))
password = forms.PasswordField( validator = v.MinLength(7,
not_empty = True))
password_repeat = forms.PasswordField()
gender = forms.SingleSelectField(
options = [ "male", "female" ]
)
validators = v.Schema(chained_validators =
v.FieldsMatch('password','password_repeat'))


register = RegisterForm('post_register')

--- snip ---

I spare you the templates and controllers, as those stuff seems to
work, the validators return errors and so on. So, how do I have to
implement such a Schema on top of tw that it will moan if the two
passwords don't match?

Thanks in advance,
Jens

Alberto Valverde

unread,
Jul 18, 2008, 6:08:12 AM7/18/08
to toscawidge...@googlegroups.com

>
> (...)

That code should work... err, no, you've got a typo there, try:

validator = v.Schema(...)
(without the trailing s)

Alberto

Jens Hoffrichter

unread,
Jul 18, 2008, 8:54:42 AM7/18/08
to toscawidge...@googlegroups.com
Hi,

2008/7/18 Alberto Valverde <alb...@toscat.net>:


> That code should work... err, no, you've got a typo there, try:
>
> validator = v.Schema(...)
> (without the trailing s)

I was SURE I had tried that, as I have tried a lot of stuff last
night. But you are right, it works like that :) You just need to put
the chained_validators in a list, like chained_validators = [
v.FieldsMatchValidator(...) ], otherwise tw can't iterate over it.

Thanks for the help :)

Jens

Reply all
Reply to author
Forward
0 new messages