Opened 4 years ago

Closed 4 years ago

#31522 closed Cleanup/optimization (fixed)

FilteredSelectMultiple widget jumps to top when an option is added.

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

Description

When using a FilteredSelectMultiple as a widget for a MultipleChoice field, typically the list of options is longer than what fits in the control. If the user then scrolls down, selects some options, and clicks the arrow to move them to the "chosen" box, then they are correctly added, but the "available" box scrolls to the top.

It would be much nicer if the "available" box stayed where it was.

At Matific where we encountered this, we monkeypatched the control's media to add a JavaScript file with this code:

(function($){
    if(!SelectBox)
        return;

    var oldRedisplay = SelectBox.redisplay;

    if(typeof oldRedisplay !== 'function')
        return;

    SelectBox.redisplay = function(id) {
        var top = $('#'+id).scrollTop(); //record current scroll
        var res = oldRedisplay.apply(this, arguments);
         $('#'+id).scrollTop(top); // Restore the scroll
        return res;
    };
})(django.jQuery);

I'm attaching a minimal project to demonstrate it.

Attachments (1)

multiselect.tgz (7.3 KB ) - added by Shai Berger 4 years ago.
This project has a user "shai" with password "1" to log in to the admin in the included database

Download all attachments as: .zip

Change History (11)

by Shai Berger, 4 years ago

Attachment: multiselect.tgz added

This project has a user "shai" with password "1" to log in to the admin in the included database

comment:1 by Shai Berger, 4 years ago

Component: Uncategorizedcontrib.admin
Easy pickings: set
UI/UX: set

comment:2 by Shai Berger, 4 years ago

Type: UncategorizedBug

comment:3 by TapanGujjar, 4 years ago

Owner: changed from nobody to TapanGujjar
Status: newassigned

comment:4 by Mariusz Felisiak, 4 years ago

Summary: FilteredSelectMultiple widget jumps to top when an option is addedFilteredSelectMultiple widget jumps to top when an option is added.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:6 by Mariusz Felisiak, 4 years ago

Patch needs improvement: set

comment:7 by TapanGujjar, 4 years ago

Cc: TapanGujjar added

comment:8 by TapanGujjar, 4 years ago

Patch needs improvement: unset

https://github.com/django/django/pull/12833

All the tests have passed. Thank you @felixxm

Last edited 4 years ago by TapanGujjar (previous) (diff)

comment:9 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 2d672224:

Fixed #31522 -- Made admin's SelectBox preserve scroll position.

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