Opened 15 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)

screenshot_inline_empty.png (14.2 KB ) - added by Martin Mahner 15 years ago.
11277-admin-hiddeninput-helpers.diff (830 bytes ) - added by Ben Boyd <beathan@…> 13 years ago.
11277-admin-hiddeninput-fieldset.html.diff (1002 bytes ) - added by Ben Boyd <beathan@…> 13 years ago.
testproject.tgz (7.8 KB ) - added by Pieter Swinkels 13 years ago.
test project to reproduce the reported problem

Download all attachments as: .zip

Change History (25)

by Martin Mahner, 15 years ago

Attachment: screenshot_inline_empty.png added

comment:1 by Alex Gaynor, 15 years ago

a) What fields on are Location

b) What do you expect to happen?

comment:2 by Alex Gaynor, 15 years ago

Resolution: worksforme
Status: newclosed

No new information after 2 months, closing as worksforme.

comment:3 by Narcélio Filho, 14 years ago

Resolution: worksforme
Status: closedreopened

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 Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Julien Phalip, 13 years ago

#14372 was closed as dupe and contains a patch.

comment:6 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

by Ben Boyd <beathan@…>, 13 years ago

by Ben Boyd <beathan@…>, 13 years ago

comment:7 by Ben Boyd <beathan@…>, 13 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 Ben Boyd <beathan@…>, 13 years ago

Easy pickings: set

comment:9 by Pieter Swinkels, 13 years ago

UI/UX: unset

DjangoCon Europe 2011 sprint: commenced work on this ticket

comment:10 by Julien Phalip, 13 years ago

UI/UX: set

by Pieter Swinkels, 13 years ago

Attachment: testproject.tgz added

test project to reproduce the reported problem

comment:10 by Pieter Swinkels, 13 years ago

UI/UX: unset

I tested it with the project I just attached but I cannot reproduce the problem.

comment:11 by beathan@…, 13 years ago

Has patch: set

comment:12 by Julien Phalip, 13 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 thepapermen, 12 years ago

Cc: thepapermen added

comment:14 by Radosław Sieradzki, 11 years ago

Keywords: sprint2013 added

comment:15 by chrismedrela, 11 years ago

Cc: chrismedrela added
Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Pull request: https://github.com/django/django/pull/789. Reviewed by rsiera.

comment:16 by rm_, 11 years ago

Cc: riccardo.magliocchetti@… added

comment:17 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:18 by Tim Graham, 11 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Patch no longer applies cleanly.

comment:19 by Russell Keith-Magee, 11 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 Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In dc3d2ac98c1bcfad74d3e9523caf07e7e9fb15aa:

Fixed #11277 -- Hid labels of fields with HiddenInput widget in admin forms.

Thanks bartTC for the report.

Note: See TracTickets for help on using tickets.
Back to Top