Opened 14 years ago

Closed 9 years ago

#14402 closed Bug (fixed)

help_text is not displayed for ManyToMany raw_id fields

Reported by: Germano Gabbianelli Owned by: Sasha Gaevsky
Component: contrib.admin Version: dev
Severity: Normal Keywords: raw_id_fields
Cc: Germano Gabbianelli, chris@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

if db_field.name in self.raw_id_fields:
    kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel, using=db)
    kwargs['help_text'] = ''

In contrib.admin.options.BaseModelAdmin.formfield_for_manytomany the help_text is reset to "" because otherwise ManyToManyField.__init__ would append 'Hold down "Control", or "Command"...' to it:

msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
self.help_text = string_concat(self.help_text, ' ', msg)

Attachments (1)

14402.diff (7.5 KB ) - added by Ramiro Morales 14 years ago.
Patch, includes tests

Download all attachments as: .zip

Change History (18)

comment:1 by Carl Meyer, 14 years ago

Triage Stage: UnreviewedAccepted
Version: 1.2SVN

Yes, not sure what the right solution is, but it should be possible to set custom help text for an m2m raw id widget.

by Ramiro Morales, 14 years ago

Attachment: 14402.diff added

Patch, includes tests

comment:2 by Ramiro Morales, 14 years ago

Has patch: set

The attached fix involves moving the "Hold down the Control key..." literal as the default help_text from its historically location in the model M2M field to the respective form field (ModelMultipleChoiceField). This way, it's available to the default form widget and the admin-specific FilteredSelectMultiple widget.

In IRC discussions, one idea suggested was to push this even more in the presentation layer by moving it to the widget realm (that would be more correct because it wouldn't force that help text on potential custom widgets whose operation doesn't involve selecting things with mouse clicks and Contrl/Command keypresses). The only problem I see with this is that it would mean we should put and maintain the "Hold down the Control key..." literal in two locations (SelectMultiple and FilteredSelectMultiple). Hopefully the tests contained in the patch are of help if this is the chosen path.

in reply to:  2 comment:3 by Germano Gabbianelli, 14 years ago

Replying to ramiro:

The attached fix involves moving the "Hold down the Control key..." literal as the default help_text from its historically location in the model M2M field to the respective form field (ModelMultipleChoiceField). This way, it's available to the default form widget and the admin-specific FilteredSelectMultiple widget.

It's surely a good thing to move it away from ManyToManyField, because otherwise it won't be possible to recover the original help_text set by the user.
However I don't understand what do you mean by saying that it's available to the widgets. ( I can't find neither in admin/widgets.py nor in forms/widgets.py how and where help_text is used by any widget ).

In IRC discussions, one idea suggested was to push this even more in the presentation layer by moving it to the widget realm (that would be more correct because it wouldn't force that help text on potential custom widgets whose operation doesn't involve selecting things with mouse clicks and Contrl/Command keypresses). The only problem I see with this is that it would mean we should put and maintain the "Hold down the Control key..." literal in two locations (SelectMultiple and FilteredSelectMultiple). Hopefully the tests contained in the patch are of help if this is the chosen path.

Granted that I wouldn't know how to do it, I think this is the only good solution. Maintaining two strings one for each widget that requires it doesn't seem a problem to me.
I am saying this because your patch doesn't seem to fix the problem. Infact you moved the help_text to ModelMultipleChoiceField but raw_id fields use that formfield too.
This means that the inappropriate help_text, for raw_id fields, will get appended to their help_texts. Actually what you did forces raw_id field to always have at least the "Hold down the Control key..." inappropriate help_text.

Moreover about the template file, using field.field.field.help_text or field.field.help_text shouldn't be different because field is an AdminField, field.field is a forms.BoundField and its help text is set like this:

self.help_text = field.help_text or ''

(I have not tested the differences, though.)

comment:4 by anonymous, 14 years ago

Cc: Germano Gabbianelli added

comment:5 by Ramiro Morales, 14 years ago

Patch needs improvement: set

See also #6183.

comment:6 by Chris Adams, 14 years ago

Cc: chris@… added

comment:7 by Julien Phalip, 14 years ago

milestone: 1.4

I think this is the manifestation of a broader issue in #9321. I recommend solving both those tickets at once.

comment:8 by Julien Phalip, 14 years ago

Easy pickings: unset
Severity: Normal
Type: Bug

Just pointing out that I have just attached a patch to #9321 which would solve both tickets at once thanks to the introduction of a new Widget.alter_help_text method.

comment:9 by Julien Phalip, 14 years ago

UI/UX: set

comment:10 by Jacob, 13 years ago

milestone: 1.4

Milestone 1.4 deleted

comment:11 by Ramiro Morales, 12 years ago

#20071 was a duplicate.

comment:12 by Ramiro Morales, 12 years ago

Description: modified (diff)

comment:13 by Collin Anderson, 10 years ago

Keywords: raw_id_fields added

comment:14 by Tim Graham, 9 years ago

This remains an issue as of 7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c (Django 1.10.dev). I didn't track it further, but in contrib/admin/templates/admin/includes/fieldset.html {{ field.field.help_text }} doesn't contain the expected help text if a field appears in raw_id_fields.

comment:15 by Sasha Gaevsky, 9 years ago

Owner: changed from nobody to Sasha Gaevsky
Patch needs improvement: unset
Status: newassigned
UI/UX: unset

comment:16 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:17 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In c79852ac:

Fixed #14402 -- Removed clearing of help_text for ManyToManyField's raw_id_fields.

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