Deform/Colander validator that has access to all nodes?

后端 未结 2 782
孤独总比滥情好
孤独总比滥情好 2021-02-15 16:44

How do you define a custom validator in Deform/Colander that has access to all node values. I need to access the values from two fields in order to decide if a particular value

2条回答
  •  执笔经年
    2021-02-15 17:25

    Tangibly the answer is:

    def verify_email_validator(form, values):
        if values['email_address'] != values['verify_email']:
            raise Invalid(form, 'Email values do not match')
    
    class MySchema(MappingSchema):
    
        def __init__(self, *args, **kwargs):
            super(KickEntrySchema, self).__init__(*args, **kwargs)
            self.validator=verify_email_validator  # entire form validator
    
        email_address = SchemaNode(Email())
        verify_email = SchemaNode(Email())
    

    Note the form validator is invoked only if none of the individual field validators raise an error.

提交回复
热议问题