Opened 3 weeks ago

Closed 2 weeks ago

#36723 closed Cleanup/optimization (fixed)

Dead JS code attempting to reposition FilteredSelectMultiple widget

Reported by: Jacob Walls Owned by: Varun Kasyap Pentamaraju
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

There is code in SelectFilter2.js that appears to reposition a help text for a FilteredSelectMultiple above the controls, but it doesn't work for two reasons:

  • it searches for a help text in a <p> tag, but it became a <div> in #27207
  • to find the wanted help text today, it now would need to start its search two parents higher (#34383 looks relevant, but I didn't verify if already an issue before that)

In other words, if we want this code to work, it would need to be like:

  • django/contrib/admin/static/admin/js/SelectFilter2.js

    diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js
    index 2100280220..beb50fb5e2 100644
    a b Requires core.js and SelectBox.js.  
    1818            from_box.setAttribute('aria-labelledby', field_id + '_from_label');
    1919            from_box.setAttribute('aria-describedby', `${field_id}_helptext ${field_id}_choose_helptext`);
    2020
    21             for (const p of from_box.parentNode.getElementsByTagName('p')) {
    22                 if (p.classList.contains("info")) {
    23                     // Remove <p class="info">, because it just gets in the way.
    24                     from_box.parentNode.removeChild(p);
    25                 } else if (p.classList.contains("help")) {
     21            const parentOfFlexContainer = from_box.parentNode.parentElement.parentElement;
     22            for (const div of parentOfFlexContainer.getElementsByTagName('div')) {
     23                if (div.classList.contains("info")) {
     24                    // Remove <div class="info">, because it just gets in the way.
     25                    parentOfFlexContainer.removeChild(div);
     26                } else if (div.classList.contains('help')) {
    2627                    // Move help text up to the top so it isn't below the select
    2728                    // boxes or wrapped off on the side to the right of the add
    2829                    // button:
    29                     from_box.parentNode.insertBefore(p, from_box.parentNode.firstChild);
     30                    parentOfFlexContainer.insertBefore(div, parentOfFlexContainer.firstChild);
    3031                }
    3132            }

In order to have:
.

Rather than:
.

To reproduce, just visit the admin, edit a user, view the permissions select widget, observe placement of the help text.

Attachments (2)

main.png (67.6 KB ) - added by Jacob Walls 3 weeks ago.
patch.png (67.1 KB ) - added by Jacob Walls 3 weeks ago.

Download all attachments as: .zip

Change History (7)

by Jacob Walls, 3 weeks ago

Attachment: main.png added

by Jacob Walls, 3 weeks ago

Attachment: patch.png added

comment:1 by Antoliny, 3 weeks ago

Triage Stage: UnreviewedAccepted

Thank you, Jacob.

It seems more appropriate for the help text to be positioned above the widget, as it was before. We are also working on rearranging the order of help text, field, and error messages.

For now, would it be better to move the help text to the top and then remove the related code in PR #34643 later? The only concern is that, if we leave it as is, only the FilteredSelect widget will have its help text positioned above for the time being.

comment:2 by Varun Kasyap Pentamaraju, 3 weeks ago

Owner: set to Varun Kasyap Pentamaraju
Status: newassigned

Willing to contribute

comment:3 by Varun Kasyap Pentamaraju, 3 weeks ago

Has patch: set

comment:4 by Jacob Walls, 2 weeks ago

Summary: Help text appears below FilteredSelectMultiple's select controlsDead JS code attempting to reposition FilteredSelectMultiple widget
Triage Stage: AcceptedReady for checkin
Type: BugCleanup/optimization
Version: 6.0dev

comment:5 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

Resolution: fixed
Status: assignedclosed

In 5c607635:

Fixed #36723 -- Removed logic for repositioning FilteredSelectMultiple help text.

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