Opened 5 years ago

Last modified 7 months ago

#14402 new Bug

help_text is not displayed for ManyToMany raw_id fields

Reported by: tyrion Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: raw_id_fields
Cc: tyrion, chris@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description (last modified by ramiro)

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 5 years ago.
Patch, includes tests

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.2 to SVN

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

Changed 5 years ago by ramiro

Patch, includes tests

comment:2 follow-up: Changed 5 years ago by ramiro

  • 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.

comment:3 in reply to: ↑ 2 Changed 5 years ago by tyrion

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 Changed 5 years ago by anonymous

  • Cc tyrion added

comment:5 Changed 4 years ago by ramiro

  • Patch needs improvement set

See also #6183.

comment:6 Changed 4 years ago by acdha

  • Cc chris@… added

comment:7 Changed 4 years ago by julien

  • milestone set to 1.4

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

comment:8 Changed 4 years ago by julien

  • Easy pickings unset
  • Severity set to Normal
  • Type set to 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 Changed 4 years ago by julien

  • UI/UX set

comment:10 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:11 Changed 2 years ago by ramiro

#20071 was a duplicate.

comment:12 Changed 2 years ago by ramiro

  • Description modified (diff)

comment:13 Changed 7 months ago by collinanderson

  • Keywords raw_id_fields added
Note: See TracTickets for help on using tickets.
Back to Top