Code

Opened 6 years ago

Closed 6 years ago

#7229 closed (duplicate)

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

Reported by: simon Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-blocker
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (2)

comment:1 Changed 6 years ago by Karen Tracey <kmtracey@…>

  • Keywords nfa-blocker added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by Karen Tracey <kmtracey@…>

  • Resolution set to duplicate
  • Status changed from new to closed

Looks like #6809 reports the same problem.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.