Opened 16 years ago
Closed 11 years ago
#11277 closed Bug (fixed)
Hidden fields in Inlines are displayed as empty rows
Reported by: | Martin Mahner | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | admin inlines hiddeninput sprint2013 |
Cc: | thepapermen, chrismedrela, riccardo.magliocchetti@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | yes |
Description
A field with an Hiddeninput widget is displayed as an empty row in the inline in admin. See screenshot for explanation.
Here is the code I use:
class LocationForm(forms.ModelForm): latitude = forms.FloatField(widget=forms.HiddenInput) longitude = forms.FloatField(widget=forms.HiddenInput) class LocationInline(generic.GenericStackedInline): model = Location form = LocationForm extra = 1 max_num = 1
Attachments (4)
Change History (25)
by , 16 years ago
Attachment: | screenshot_inline_empty.png added |
---|
comment:1 by , 16 years ago
comment:2 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
No new information after 2 months, closing as worksforme.
comment:3 by , 15 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
The issue is that labels are still being rendered on forms, even when the field is hidden. Labels should not be rendered if field is hidden, right?
(Maybe the problem is at django/contrib/admin/templates/admin/includes/fieldset.html or AdminField.label_tag().)
Checkout a discussion about that:
How do I hide the field label for a HiddenInput widget in Django Admin?
comment:4 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
by , 14 years ago
Attachment: | 11277-admin-hiddeninput-helpers.diff added |
---|
by , 14 years ago
Attachment: | 11277-admin-hiddeninput-fieldset.html.diff added |
---|
comment:7 by , 14 years ago
Easy pickings: | unset |
---|
I've attached 2 diffs as a proposed patch for this issue, tested on the latest trunk. One adds has_hidden_field to Fieldline in django/contrib/admin/helpers.py, marking it True if self.fields contains a field with a hidden widget, and another for django/contrib/admin/templates/admin/includes/fieldset.html, which outputs only the fields themselves if line.has_hidden_field is True.
comment:8 by , 14 years ago
Easy pickings: | set |
---|
comment:9 by , 14 years ago
UI/UX: | unset |
---|
DjangoCon Europe 2011 sprint: commenced work on this ticket
comment:10 by , 14 years ago
UI/UX: | set |
---|
comment:10 by , 14 years ago
UI/UX: | unset |
---|
I tested it with the project I just attached but I cannot reproduce the problem.
comment:11 by , 14 years ago
Has patch: | set |
---|
comment:12 by , 14 years ago
Easy pickings: | unset |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
UI/UX: | set |
The patch needs tests. It also needs to cater for when the Fieldline
contains only one, hidden, field (in which case the entire row, including the label and help_text, show be hidden -- see #7859 and #14372), or when it contains a mix of hidden and non-hidden fields (in which case the row should be displayed and the non-hidden fields should also be displayed correctly).
By the way, I could reproduce the issue with the following code:
# models.py from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class Restaurant(models.Model): name = models.CharField(max_length=200) class Location(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') longitude = models.FloatField(blank=True) latitude = models.FloatField(blank=True) # admin.py from django.contrib import admin from django import forms from django.contrib.contenttypes.generic import GenericStackedInline from .models import Restaurant, Location class LocationForm(forms.ModelForm): latitude = forms.FloatField(widget=forms.HiddenInput) longitude = forms.FloatField(widget=forms.HiddenInput) class LocationInline(GenericStackedInline): model = Location form = LocationForm extra = 1 max_num = 1 class RestaurantAdmin(admin.ModelAdmin): inlines = [LocationInline] admin.site.register(Restaurant, RestaurantAdmin)
This is however not tied to generic inlines in particular, but is relevant to any form of any kind (main forms, regular inline forms and generic inline forms).
comment:13 by , 13 years ago
Cc: | added |
---|
comment:14 by , 12 years ago
Keywords: | sprint2013 added |
---|
comment:15 by , 12 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Pull request: https://github.com/django/django/pull/789. Reviewed by rsiera.
comment:16 by , 12 years ago
Cc: | added |
---|
comment:17 by , 12 years ago
Status: | reopened → new |
---|
comment:18 by , 12 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Patch no longer applies cleanly.
comment:19 by , 12 years ago
Pull request #1260 was provided as a fix for this ticket; still not RFC, though. Comments on the pull request.
comment:20 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
a) What fields on are Location
b) What do you expect to happen?