I am using a form widget, and have defined a form level custom
validator to verify two fields combined. In case of error, I want to
show error message only beside one of these two fields. But the error
message comes beside every field in the form.
Needing suggestion. The problem seems similar to the one discussed at
http://groups.google.co.in/group/turbogears/browse_thread/thread/d238edd1dc04b774/ef970f4fa395516c
thanks
sanjay
>
> Hi All,
>
> I am using a form widget, and have defined a form level custom
> validator to verify two fields combined. In case of error, I want to
> show error message only beside one of these two fields. But the error
> message comes beside every field in the form.
Take a look at the code of FieldsMatch from formencode (for example).
As the validator works on the whole form you need to build an error
dict and place the error in the field's key you want the error to
appear at.
something like:
def validate_python(self, field_dict, state=None):
errors = {}
if there_is_an_error:
errors['foo'] = "Invalid input at foo"
raise Invalid("The form contains an error", field_dict,
state, error_dict=errors)
Alberto
sanjay