Opened 14 years ago

Closed 14 years ago

Last modified 10 years ago

#14372 closed Uncategorized (duplicate)

Admin shouldn't render label tags on hidden fields

Reported by: Michael Newman Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin hiddenfields forms
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If a field in the admin is hidden, the label tag is still rendered. It would be pretty easy to not have that happen anymore. See patch attached.

Attachments (1)

14372-admin-hiddenfield.diff (797 bytes ) - added by Michael Newman 14 years ago.
Simple check to is_hidden to determine if we should render the label.

Download all attachments as: .zip

Change History (5)

by Michael Newman, 14 years ago

Simple check to is_hidden to determine if we should render the label.

comment:1 by Ramiro Morales, 14 years ago

Triage Stage: UnreviewedAccepted

See also the patch attached to #7859.

comment:2 by Julien Phalip, 14 years ago

Needs tests: set
Patch needs improvement: set

The patch is not ideal. With that patch, if the row contains just one field and that field is hidden, then you're left with an empty <div class="form-row title">. The patch should be improved to not display the row at all in this case.

comment:3 by Julien Phalip, 14 years ago

Resolution: duplicate
Status: newclosed

This is effectively a dupe of #11277.

comment:4 by django@…, 10 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

Aloha,

I use the following snippet as fieldset.html.

It not only hides the input field instead if the fieldset contains only a single element which input-type is set to hidden it also hides the surrounding div-elements. So no space is wasted.

The snippet inserts the style-attribute with display: none. Others may prefer to insert a css class. But this way no one has to edit the admins css.

Maybe someone could test if this solution has side effects in other cases.

Regards, lacki

<fieldset class="module aligned {{ fieldset.classes }}">
    {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
    {% if fieldset.description %}
        <div class="description">{{ fieldset.description|safe }}</div>
    {% endif %}
    {% for line in fieldset %}
        <div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}"{% if line.fields|length_is:'1' %}{% for field in line %}{% if field.field.is_hidden %} style="display: none"{% endif %}{% endfor %}{% endif %}>
            {% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %}
            {% for field in line %}
                <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}"{% endif %}{% if field.field.is_hidden %} style="display: none"{% endif %}>
                    {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
                    {% if field.is_checkbox %}
                        {{ field.field }}{{ field.label_tag }}
                    {% else %}
                        {# only show the label for visible fields #}
                        {% if not field.field.is_hidden %}
                        {{ field.label_tag }}
                        {% endif %}

                        {% if field.is_readonly %}
                            <p>{{ field.contents }}</p>
                        {% else %}
                            {{ field.field }}
                        {% endif %}
                    {% endif %}
                    {% if field.field.help_text %}
                        <p class="help">{{ field.field.help_text|safe }}</p>
                    {% endif %}
                </div>
            {% endfor %}
        </div>
    {% endfor %}
</fieldset>
Note: See TracTickets for help on using tickets.
Back to Top