WTForms validators.optional: continue validation of empty fields?

I have a problem with WTForms validators.optional() because it stops the validation chain if the field is empty (WTForms docs). This means that the validation does not continue with custom functions, which can result in type errors.

Code example:

class MyForm(form):
    myfield = TextField('My Field', [validators.Optional()])

    def validate_myfield(form, field):
        field.data = unicode(field.data)

Is there any way or workaround to continue the validation chain even if the optional content is empty, maybe using custom validators?

If I am approaching the problem in the wrong way, a hint at the right direction would be helpful!

5
задан lecodesportif 1 April 2011 в 11:01
поделиться