Opened 10 years ago

Closed 8 years ago

Last modified 5 years ago

#2612 closed defect (fixed)

Fix admin formatting when help_text used with multiple fields on the same line

Reported by: Andy Dustman <farcepest@…> Owned by: xian
Component: contrib.admin Version: master
Severity: minor Keywords: nfa-someday
Cc: farcepest@…, andy@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

Description

If you have a case where you have set multiple fields to appear on the same line in the admin interface, the current version produces a line break when help_text is present, due to it being in a <p> element. To fix it in a half-assed sort of way, I wrapped the entire field in a <div style="float: left">. The diff is should below:

Index: django/contrib/admin/templates/admin/field_line.html
===================================================================
--- django/contrib/admin/templates/admin/field_line.html        (revision 3669)
+++ django/contrib/admin/templates/admin/field_line.html        (working copy)
@@ -2,9 +2,11 @@
 <div class="{{ class_names }}" >
 {% for bound_field in bound_fields %}{{ bound_field.html_error_list }}{% endfor %}
 {% for bound_field in bound_fields %}
+ <div style="float: left;">
   {% if bound_field.has_label_first %}{% field_label bound_field %}{% endif %}
   {% field_widget bound_field %}
   {% if not bound_field.has_label_first %}{% field_label bound_field %}{% endif %}
   {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %}
+ </div>
 {% endfor %}
 </div>

Ultimately you want a class which does this, which means changing the admin stylesheet, so you probably don't want to use this patch exactly.

The patch does not appear to affect the default case of stacked fields, as the the field line itself is wrapped in another <div>.

Attachments (6)

admin-formatting.diff (1.7 KB) - added by Andy Dustman <farcepest@…> 10 years ago.
Proper patch for the fix. Adds a form-row-item class and applies it with a div around every bound_field
help_text_patch.diff (887 bytes) - added by hakejam 9 years ago.
2612-multiple-fields-on-line.1.diff (903 bytes) - added by Brian Rosner 8 years ago.
updated to r8388
admin_inlines.diff (3.5 KB) - added by nathan 8 years ago.
This one's better
admin_inlines.2.diff (3.5 KB) - added by nathan 8 years ago.
Admin inline float fix
ticket2612-r8860.diff (4.2 KB) - added by Jannis Leidel 8 years ago.
Fix that doesn't patch float-left class and is rtl compatible.

Download all attachments as: .zip

Change History (27)

Changed 10 years ago by Andy Dustman <farcepest@…>

Attachment: admin-formatting.diff added

Proper patch for the fix. Adds a form-row-item class and applies it with a div around every bound_field

comment:1 Changed 9 years ago by Chris Beaven

I can confirm this patch fixes the above problem. I would upload before / after screenshots but trac won't let me.

Probably needs some more testing to make sure this doesn't break any existing fields.

Changed 9 years ago by hakejam

Attachment: help_text_patch.diff added

comment:2 Changed 9 years ago by hakejam

Needs tests: set
Triage Stage: UnreviewedAccepted

Expanded on the idea above using the float-left css class that was already in the admin. I have tested it with a few examples, but still needs more testing. Not sure if this applies to the newforms-admin branch.

comment:3 Changed 9 years ago by hakejam

Resolution: fixed
Status: newclosed
Triage Stage: AcceptedReady for checkin

comment:4 Changed 9 years ago by hakejam

Keywords: sprintsept14 added

comment:5 Changed 9 years ago by Simon G. <dev@…>

Resolution: fixed
Status: closedreopened

It's not closed until it's checked in

comment:6 Changed 9 years ago by Gary Wilson

Patch needs improvement: set
Summary: [patch] Fix admin formatting when help_text used with multiple fields on the same lineFix admin formatting when help_text used with multiple fields on the same line
Triage Stage: Ready for checkinAccepted
Version: SVNnewforms-admin

This needs to be fixed in newforms-admin, as it will soon will be replacing the current admin.

comment:7 Changed 9 years ago by xian

Keywords: help_text added
Owner: changed from nobody to xian
Status: reopenednew

Assigning to myself to make sure it gets attended to in newforms-admin. We're allowing stacked inlines to take full fieldsets so we have a there will be edge cases there to work out.

comment:8 Changed 9 years ago by Karen Tracey <kmtracey@…>

Keywords: nfa-someday added; sprintsept14 help_text removed

Formatting improvement for a problem that was noted in old admin, should not block newforms-admin merge.

comment:9 Changed 8 years ago by Jeff Anderson

milestone: 1.0

Changed 8 years ago by Brian Rosner

updated to r8388

comment:10 Changed 8 years ago by Brian Rosner

I attached a patch that applies on the latest trunk (r8388). I am not a UI designer nor really that great with front-end work. However, this does fix the problem of the line break, but doesn't seem 100% ideal. Also if there is no help_text on the first field in a two field grouping, but help_text on the second one, then the latter's help_text is placed under the first. Ideally someone with better skills in this area is required. :)

comment:11 Changed 8 years ago by Brian Rosner

Closed #7054 as a duplicate. The patch there provides a fix to the problem I described in my last comment.

comment:12 Changed 8 years ago by Manuel Saelices

I've tried to test this ticket, but I've not found right admin options for placing two fields in same line. I've been trying with this, but I didn't find the correct CSS class for placing into same line:

# model:
class Person(models.Model):
    name = models.CharField(max_length=128, help_text="Please input the name")
    date_joined = models.DateTimeField()

# admin:
class PersonAdmin(admin.ModelAdmin):
    fieldsets = (('Avanced options', {'classes': '????????', # what CSS class?
                                      'fields': ('person', 'date_joined')}),)

What CSS class we use? Is correct this approach to reproduce UI bug?

comment:13 Changed 8 years ago by Manuel Saelices

Sorry for previous comment, correct last line was:

'fields': ('name', 'date_joined')}),)

comment:14 Changed 8 years ago by Malcolm Tredinnick

Version: newforms-adminSVN

@msaelices: don't worry about testing this. Jacob and I sat down with a designer (Nathan Borror) last week and discussed this. He's going to look at some solutions that will work. We'll use whatever he comes up with. (By the way, the feature you were looking for is fieldsets and then tuples of fields).

comment:15 Changed 8 years ago by Manuel Saelices

@mtredinnick, ok. I'll wait :-P, but, I think fieldsets is just I put in my PersonAdmin options, isn't?

comment:16 Changed 8 years ago by Brian Rosner

Resolution: fixed
Status: newclosed

(In [8824]) Fixed #2612 -- Fixed admin formatting when help_text is used with multiple fields on the same line.

Changed 8 years ago by nathan

Attachment: admin_inlines.diff added

This one's better

Changed 8 years ago by nathan

Attachment: admin_inlines.2.diff added

Admin inline float fix

comment:17 Changed 8 years ago by Alex Gaynor

Resolution: fixed
Status: closedreopened

Reopening since we now have a patch from nathan, a real designer :P

comment:18 Changed 8 years ago by Jannis Leidel

With all due respect patching a global CSS class like .float-left seems unreasonable, creating an own class should also work.

Also, please fix it for rtl-languages.

Changed 8 years ago by Jannis Leidel

Attachment: ticket2612-r8860.diff added

Fix that doesn't patch float-left class and is rtl compatible.

comment:19 Changed 8 years ago by Jacob

Resolution: fixed
Status: reopenedclosed

Fixed in [8871].

comment:20 Changed 8 years ago by anonymous

Cc: andy@… added

comment:21 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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