Re: [Django] #14372: Admin shouldn't render label tags on hidden fields

2 views
Skip to first unread message

Django

unread,
May 31, 2014, 5:08:14 AM5/31/14
to django-...@googlegroups.com
#14372: Admin shouldn't render label tags on hidden fields
-------------------------------------+-------------------------------------
Reporter: Mnewman | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: duplicate
Keywords: admin hiddenfields | Triage Stage: Accepted
forms | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by django@…):

* ui_ux: => 0
* type: => Uncategorized
* severity: => Normal
* easy: => 0


Comment:

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>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/14372#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages