Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#212 closed defect (fixed)

help_text is not displayed for ManyToManyField in the admin interface

Reported by: jkocherhans@… Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description


Change History (3)

comment:1 Changed 10 years ago by jkocherhans@…

The <p class="help_text"> tag is showing up in the source... I think the javascript for the multiple select boxes is overwriting it somehow. Looking into it more.

comment:2 Changed 10 years ago by jkocherhans@…

Ok, the javascript overwrites it on purpose... I don't think that's necessary. The code in django/conf/admin_media/js/SelectFilter2.js replaces the contents of the parent of the form element with id="id_fieldname" so if we wrap the form element in an extra <div>, only the contents of that div get replaced... the help paragraph stays untouched.

Here's a few possible fixes:

Wrap every form element in an extra <div>:

Index: django/views/admin/main.py
===================================================================
--- django/views/admin/main.py  (revision 569)
+++ django/views/admin/main.py  (working copy)
@@ -717,7 +717,7 @@
             if i > 0:
                 class_names.append('inline')
             t.append('<label for="%s"%s>%s:</label> ' % (label_name, class_names and ' class="%s"' % ' '.join(class_names) or '', capfirst(field.verbose_name)))
-            t.append(_get_admin_field_form_widget(field, name_prefix, rel, add, change))
+            t.append("<div>%s</div>" % _get_admin_field_form_widget(field, name_prefix, rel, add, change))
         if change and field.primary_key:
             t.append('{{ %soriginal.%s }}' % ((rel and name_prefix or ''), field.name))
         if change and use_raw_id_admin(field):

Wrap <select> fields in an extra <div>:

===================================================================
--- django/views/admin/main.py  (revision 569)
+++ django/views/admin/main.py  (working copy)
@@ -717,7 +717,11 @@
             if i > 0:
                 class_names.append('inline')
             t.append('<label for="%s"%s>%s:</label> ' % (label_name, class_names and ' class="%s"' % ' '.join(class_names) or '', capfirst(field.verbose_name)))
-            t.append(_get_admin_field_form_widget(field, name_prefix, rel, add, change))
+            widget_str = _get_admin_field_form_widget(field, name_prefix, rel, add, change)
+            if isinstance(field.rel, meta.ManyToMany):
+                t.append("<div>%s</div>" % widget_str)
+            else:
+                t.append(widget_str)
         if change and field.primary_key:
             t.append('{{ %soriginal.%s }}' % ((rel and name_prefix or ''), field.name))
         if change and use_raw_id_admin(field):

The other option I see is to use something custom instead of quickElement in django/conf/admin_media/js/SelectFilter2.js I'd rather not touch the javascript.

comment:3 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

This was fixed a while back.

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