After reading over the newforms documentation, I came across the
Form.clean() method that suites my case nicely regarding my newforms-
admin form:

"""
The Form subclass’s clean() method. This method can perform any
validation that requires access to multiple fields from the form at
once. This is where you might put in things to check that if field A
is supplied, field B must contain a valid email address and the like.
The data that this method returns is the final cleaned_data attribute
for the form, so don’t forget to return the full list of cleaned data
if you override this method (by default, Form.clean() just returns
self.cleaned_data).

Note that any errors raised by your Form.clean() override will not be
associated with any field in particular. They go into a special
“field” (called __all__), which you can access via the
non_field_errors() method if you need to.
"""

My validation across multiple form fields works now, however I can not
get an error message to be displayed on the page.
The last paragraph indicates that error(s) raised will not be
associated with any particular field(s). Can someone please explain
the last sentence in the above doc snippet with regards to the special
'field' called __all__?

regards,
-al

On Apr 30, 5:50 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi Al,
>
> On Apr 30, 2:18 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > I would like to add some custom validation to the newform-admin form.
> > I have look at the 
> > -http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIaddcustomval...
> > - and am still not finding a solution.
>
> > Here is what I'm trying to do:
>
> > I have several form fields on an admin form that correspond to a
> > relevant model.
> > I'd like to add custom validation to one of the char fields (choice
> > box) called 'status'. It needs to be validated in such a way that if a
> > value presented in another form field, named 'job_title', is blank,
> > then 'status' (choice box) can only be set to 'invalid' as an option.
>
> > The formfield method of the models.CharField is what I'd probably need
> > to override here. However, how do I get a handle on the other form
> > fields so I can do some validation logic like "if not job_title and
> > status !='I': ..then add a validation error".
>
> > Can someone please point me in the right direction.
>
> The latest version of newforms-admin has the method 'get_form' as part
> of the ModelAdmin class. If you define yourself a standard newform, as
> you would for a non-admin app then you can override the method and
> return your form.
>
> Everything should then work as usual.
>
> Not that I've tested it or anything but give it a go.
>
> Regards,
>
> Felix
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to