Code

Opened 8 years ago

Closed 6 years ago

Last modified 3 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@…> 8 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 7 years ago.
2612-multiple-fields-on-line.1.diff (903 bytes) - added by brosner 6 years ago.
updated to r8388
admin_inlines.diff (3.5 KB) - added by nathan 6 years ago.
This one's better
admin_inlines.2.diff (3.5 KB) - added by nathan 6 years ago.
Admin inline float fix
ticket2612-r8860.diff (4.2 KB) - added by jezdez 6 years ago.
Fix that doesn't patch float-left class and is rtl compatible.

Download all attachments as: .zip

Change History (27)

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

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

comment:1 Changed 7 years ago by SmileyChris

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 7 years ago by hakejam

comment:2 Changed 7 years ago by hakejam

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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 7 years ago by hakejam

  • Resolution set to fixed
  • Status changed from new to closed
  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 7 years ago by hakejam

  • Keywords sprintsept14 added

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

  • Resolution fixed deleted
  • Status changed from closed to reopened

It's not closed until it's checked in

comment:6 Changed 7 years ago by gwilson

  • Patch needs improvement set
  • Summary changed from [patch] Fix admin formatting when help_text used with multiple fields on the same line to Fix admin formatting when help_text used with multiple fields on the same line
  • Triage Stage changed from Ready for checkin to Accepted
  • Version changed from SVN to newforms-admin

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

comment:7 Changed 7 years ago by xian

  • Keywords sprintsept14, help_text added; sprintsept14 removed
  • Owner changed from nobody to xian
  • Status changed from reopened to new

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 7 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 6 years ago by programmerq

  • milestone set to 1.0

Changed 6 years ago by brosner

updated to r8388

comment:10 Changed 6 years ago by brosner

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 6 years ago by brosner

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

comment:12 Changed 6 years ago by msaelices

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 6 years ago by msaelices

Sorry for previous comment, correct last line was:

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

comment:14 Changed 6 years ago by mtredinnick

  • Version changed from newforms-admin to SVN

@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 6 years ago by msaelices

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

comment:16 Changed 6 years ago by brosner

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

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

Changed 6 years ago by nathan

This one's better

Changed 6 years ago by nathan

Admin inline float fix

comment:17 Changed 6 years ago by Alex

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:18 Changed 6 years ago by jezdez

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 6 years ago by jezdez

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

comment:19 Changed 6 years ago by jacob

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

Fixed in [8871].

comment:20 Changed 5 years ago by anonymous

  • Cc andy@… added

comment:21 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.