Multiple chained_validators possible?

1 view
Skip to first unread message

chiangf

unread,
Dec 5, 2006, 10:03:17 PM12/5/06
to TurboGears
I need more than one chained_validators in one schema. Is this
possible? I tried this:
class UserAddSchema(validators.Schema):
password = validators.String(not_empty=True)
passwordConfirm = validators.String(not_empty=True)
chained_validators = [validators.FieldsMatch('passwordConfirm',
'password')]
mytext= validators.String(not_empty=True)
mytextConfirm= validators.String(not_empty=True)
chained_validators2 = [MyTextValidator('mytext', 'mytextConfirm')]

The password validator works on its own and the MyTextValidator works
on its own as well.

Apparently there's some magic in the word 'chained_validators' because
if I change it from that word, the validator simply ignores it. When I
comment out one of the chained_validators and changed the other one to
'chained_validators', it worked. I'm aware that what I just said is
poorly worded, so this is what I mean:
class UserAddSchema(validators.Schema):
password = validators.String(not_empty=True)
passwordConfirm = validators.String(not_empty=True)
#chained_validators = [validators.FieldsMatch('passwordConfirm',
'password')]
mytext= validators.String(not_empty=True)
mytextConfirm= validators.String(not_empty=True)
chained_validators = [MyTextValidator('mytext', 'mytextConfirm')]


Does anyone know how to make 2 chained_validators in one schema?


Thanks in advance,

Frank

Patrick Lewis

unread,
Dec 5, 2006, 11:13:08 PM12/5/06
to TurboGears
You should just be able to do:

chained_validators = [validators.FieldsMatch('passwordConfirm',

'password'), MyTextValidator('mytext', 'mytextConfirm')]

chiangf

unread,
Dec 6, 2006, 9:50:12 AM12/6/06
to TurboGears
Thanks! That worked perfectly!

Reply all
Reply to author
Forward
0 new messages