#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)
Change History (5)
by , 14 years ago
Attachment: | 14372-admin-hiddenfield.diff added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
See also the patch attached to #7859.
comment:2 by , 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 , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is effectively a dupe of #11277.
comment:4 by , 11 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>
Simple check to is_hidden to determine if we should render the label.