Re: Injecting validation errors into newforms

2007-08-25 Thread Peter Melvyn

On 8/24/07, Kirk Strauser <[EMAIL PROTECTED]> wrote:

> problem I'm running into is that I'd really, really like to be able to
> associate errors from the form.clean() stage of validation with the fields
> that are actually having problems.

To assign a single message, I use following assignment:

self.errors['my_field_name'] = ErrorList(['My error message'])

For details see class ValidationError in django.newforms.util

HTH, Peter

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Injecting validation errors into newforms

2007-08-24 Thread Kirk Strauser

I'm using newforms to create self-validation input forms on my site.  The 
problem I'm running into is that I'd really, really like to be able to 
associate errors from the form.clean() stage of validation with the fields 
that are actually having problems.  For example, I'd like something like:

class MyForm(forms.Form):
def clean(self):
myerrors = longprocessonremotemachine() # returns a dict
self.errorset.update(myerrors)

and then see inline error messages in the HTML form like:

Record ID: 1234
   * This ID isn't present in our legacy system

instead of having all such errors bunched up at the top of the form.  I'm 
currently using:

def clean(self):
myerrors = longprocessonremotemachine() # returns a dict
raise forms.ValidationError('\n'.join(myerrors.values())

which does exactly that.
-- 
Kirk Strauser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---