Django

Code

Ticket #7229 (closed: duplicate)

Opened 2 months ago

Last modified 1 month ago

newforms-admin does not display validation errors that aren't associated with a particular field

Reported by: simon Assigned to: nobody
Milestone: Component: Admin interface
Version: newforms-admin Keywords: nfa-blocker
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If you attempt to add custom validation to a newforms-admin model adding/editing page that runs against more than one field (and hence should be in the form's "clean" method, rather than a clean method associated with a particular field) you run in to problems. Here's the example code:

def custom_clean(self):
    image_url = self.cleaned_data.get('image_url', None)
    image = self.cleaned_data.get('image', None)
    if not image and not image_url:
        raise forms.ValidationError("You must upload OR enter an image")
    return self.cleaned_data

class EntryOptions(admin.ModelAdmin):
    
    def get_form(self, request, obj=None):
        form = super(EntryOptions, self).get_form(request, obj)
        form.clean = custom_clean
        return form

This works in as much as you get a message about there being errors on the page, but the actual errors are not displayed anywhere. They should be displayed in a list at the top of the page.

Forms have a non_field_errors() method that can be used for this purpose.

Attachments

Change History

06/09/08 17:22:06 changed by Karen Tracey <kmtracey@gmail.com>

  • keywords set to nfa-blocker.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

06/09/08 19:14:19 changed by Karen Tracey <kmtracey@gmail.com>

  • status changed from new to closed.
  • resolution set to duplicate.

Looks like #6809 reports the same problem.


Add/Change #7229 (newforms-admin does not display validation errors that aren't associated with a particular field)




Change Properties
Action