[EMAIL PROTECTED] wrote:
> Hello guys. Maybe someone knows how to do this.
> If i have the following code:
> [two chained validators; Anm. Mark]
> 
> How do i implement MyTextValidator?
> Iam only interested in the structure of the class. How do i access the
> values of 'mytext', mytextConfirm'?

You implement it as every chained validator else. There is nothing special about
your validator being the second one.

In case you'd like to see more examples than those shipped with FormEncode, take
a look at [1].

You can make a more simpler validator validating more than one field if you know
the fields' names from the start. Additionaly, you can add error messages for
the fields separately, as done here at the very bottom (another example; to be
included as chained_validator):

class PostalCodeInCountryFormat(FancyValidator):

    messages = {
        'badFormat': _("Given postal code... country's format."),
        }
    _vd = {
        'DE': GermanPostalCode,
        # ...
        'PL': PolishPostalCode,
        'US': USPostalCode,
        'CA': CanadianPostalCode,
        'AR': ArgentinianPostalCode,
    }

    def validate_python(self, fields_dict, state):
        if fields_dict['country'] in self._vd:
            try:
                current_vd = self._vd[fields_dict['country']]
                fields_dict['zip'] = current_vd.to_python(fields_dict['zip'])
            except Invalid, exc:
                message = self.message('badFormat', state)
                raise Invalid(message, fields_dict, state,
                              error_dict = {'zip' : exc.message,
                                            'country': message})
            # ...

So, next to the zip field you can read "German postal codes' format is #####"
and next to the country field stands "Given postal code does not match...".

-- W-Mark Kubacki

[1] http://tgcaptcha.googlecode.com/svn/trunk/tgcaptcha/validator.py

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to