Opened 16 years ago
Closed 16 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: | no | UI/UX: | no |
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.
Change History (2)
comment:1 by , 16 years ago
Keywords: | nfa-blocker added |
---|
comment:2 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Looks like #6809 reports the same problem.