#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.34c9f88b87c0f779d31f177719073027%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to