Ok, I found some useful info posted by Malcolm:
"Form.errors is an ErrorDict (from newforms.util), which maps field
names
to ErrorList instances. It is important to use ErrorList classes as
the
values in that dictionary, because they know how to display themselves
properly.
I'm not really alongside any plan to do form-specific error messages
in
Form.clean() -- almost by definition, it's for errors that apply to
more
than one field simultaneously -- but if you want to tweak self.errors,
you now have the knowledge. "
I'm not really sure how to process this list in the template.. or how
it gets stored for the correct field. Suppose I have this code in
clean():
rc = 0
if 'captcha' in self.cleaned_data:
if not self.cleaned_data['imghash'] == sha.new(SALT
+self.cleaned_data['captcha']).hexdigest():
error_list.append("Captcha error!")
rc = 1
raise forms.ValidationError(_(u'CAPTCHA error!'))
if 'password1' in self.cleaned_data and 'password2' in
self.cleaned_data:
if self.cleaned_data['password1'] !=
self.cleaned_data['password2']:
error_list.append("Password mismatch!")
rc = 1
raise forms.ValidationError(_(u'You must type the same
password each time'))
if rc:
raise forms.ValidationError(error_list)
return self.cleaned_data
How does this function know to associate 'Captcha error' with
captcha ? and how do I reference it in the template?
Thanks.
Rob
On Feb 14, 1:09 pm, robstar <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I'm working my way through the newforms and it's pretty cool.. but I'm
> stumped on the error message handling from clean().
>
> I want to check the CAPTCHA input on the page (2 fields) as well as if
> the password
> fields match and return the error for each problem independently.
> clean() is supposed to let you handle code where multiple form fields
> are required and I build up a list of 0-2 errors depending on the
> scenario.
>
> How can I process which error message is for which field on the
> returned web page? Is there a way to get to the list of errors and
> know which error is for which field?
>
> Is there a way to link the ValidationError to a specific field in
> clean() ??
>
> Thanks for the help.
>
> Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---