Code

Opened 3 years ago

Last modified 8 weeks ago

#16730 new New feature

serializing forms which use FilteredSelectMultiple

Reported by: alan.kesselmann@… Owned by:
Component: contrib.admin Version: 1.3
Severity: Normal Keywords: nlsprint14
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

Hello!

This is minor but annoying problem.

I use django.contrib.admin.widgets.FilteredSelectMultiple on publicly visible page and post forms contents with ajax - gathering data with form.serialize(). When doing so i noticed that info from the select widget was not sent to server. I followed problem to django/contrib/admin/media/js/SelectBox.js and to SelectBox objects render method. The problem why jQuery.serialize() does not serialize selects contents is simply because those options arent selected after moving from one select to another. And they arent selected because SelectBox.render() is called after each moving - and after it none of the options have selected attribute.

Like i said - it is not big problem and it has workaround - you have to select the options in 2nd select if you want form.serialize() to pick up its contents. But when selects contents are many, then this is not easy. It would be much easyer if they remained selected after beeing moved from one select to another.

Alan

Attachments (0)

Change History (11)

comment:1 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • UI/UX set

comment:2 Changed 3 years ago by julien

  • Triage Stage changed from Unreviewed to Design decision needed

I see how this can be annoying in some situations like yours, however the case can also be made that keeping the items selected could be confusing for the user. What if, for example, some items in the destination list were already selected before the move? Would the moved ones be appended to the selection or would the prior selection in the destination list be cleared before re-selecting only the freshly moved ones?

comment:3 Changed 3 years ago by julien

  • Component changed from Forms to contrib.admin

comment:4 Changed 3 years ago by alan.kesselmann@…

The selected items would be appended to previous selection in destination list.

Why im so fond of this widget is that i had to create one such widget for myself for one php project. After prototyping our decision was to keep items in destination list selected all the time. Simple reason - selecting all the items in destination list again just does not make any sense. And in case of when the destination list contains more items that fit in select area, the scrolling makes selecting those items very very annoying for random browser user who usually does not know the ctrl + click and shift + click selecting options.

So it comes down to comparing those use cases :

  1. User selects items from "from" select(1). User clicks add button(2). user saves selection (3)
  2. User selects items from "from" select(1). User clicks add button(2). User has to select all the selected items again (i have heard users say - why?! i just selected those items in last box, why do i have to select them again just to save my selection?) (3). User saves selection (4).

Case II makes even less sense cause without the jquery form.serialize() the widget works exactly as case I.

comment:5 follow-up: Changed 3 years ago by julien

Could you clarify what you mean by "user saves selection"? I am a bit confused why you need to select things from the destination list.

This widget is basically to select multiple items from a pool of available options (aka the "from" list). Once an item is moved to the destination list, then it is considered "selected" in the sense that the user has decided to pick that item from the available ones. So here the only purpose of selecting items (as in clicking or ctrl-clicking) is to move them from one list to the other.

Your use case seems to involve a third step, i.e. selecting items from the pool of already selected items (i.e. already the ones present in the destination list) to operate further operations. If that's the case, then I'm afraid this is beyond the scope of what was intended for this admin widget, and if you've already got an easy workaround to hack some extra functionality on top of it then that's great but that would remain your own responsibility.

comment:6 Changed 3 years ago by julien

By the way, it would be interesting to hear if the patch in #16059 improves the general usability of that widget for you. It doesn't address the specific selection issue that you're reporting here though.

comment:7 in reply to: ↑ 5 Changed 3 years ago by alan.kesselmann@…

  • Type changed from Bug to New feature

Replying to julien:

Could you clarify what you mean by "user saves selection"? I am a bit confused why you need to select things from the destination list.


By that i mean, the intent behind this widget - Its meant to make selection of items from list easyer. I mean that the "destination" list is initially a selection of items user wants to differentiate from the "source" list and save that selection.

This widget is basically to select multiple items from a pool of available options (aka the "from" list). Once an item is moved to the destination list, then it is considered "selected" in the sense that the user has decided to pick that item from the available ones. So here the only purpose of selecting items (as in clicking or ctrl-clicking) is to move them from one list to the other.


You are absolutely correct. When you look at it from the users point of view - the items in "destination" list are selected as far as user is concerned. But in HTML sense the items from 2nd list do not differ from the items in the first list, cause none of the options have "selected" attribute. And that "selected" attribute is that jquery .serialize() uses to pick up selection for saving. So if i wanted to post this form with ajax i would have to remind users to manually select items in "destination" list again - just so jQuery .serialize() would pick them up.

Your use case seems to involve a third step, i.e. selecting items from the pool of already selected items (i.e. already the ones present in the destination list) to operate further operations. If that's the case, then I'm afraid this is beyond the scope of what was intended for this admin widget, and if you've already got an easy workaround to hack some extra functionality on top of it then that's great but that would remain your own responsibility.


Yeah true again. I pondered over it and thought that this is not necessarily django bug but rather jquery .serialize() problem. Widget might work as intended, but in that case its not intended to be easyly posted with ajax and form serializing. And instead of beeing able to use existing widget (FilteredSelectMultiple) i would have to create my own with just this small difference.

I do not have a workaround for this widget. For my project i would have to create my own widget anyway. I propose though, that existing widget could be modified to keep options in "destination" list selected - which would eliminate the need for creating own widget just when you want to post this form with jquery.

Alan

comment:8 Changed 3 years ago by jacob

  • Triage Stage changed from Design decision needed to Someday/Maybe

This is something that needs to be fixed. Sadly, it involves a fair bit of hacking on the select box JS, which is early, crufty, and fragile. Realistically this is more likely to be solved by the admin refresh/refactor we're starting to think about than by itself.

Thus, I'm marking this as "someday". Feel free to work on a patch, if you like, but I think attention would be better spent on the more general admin effort than this specific issue. There's probably a zillion like it, sadly.

Thanks!

comment:9 Changed 8 weeks ago by rednaw

  • Keywords nlsprint14 added
  • Owner changed from nobody to rednaw
  • Status changed from new to assigned

comment:10 Changed 8 weeks ago by rednaw

  • Owner rednaw deleted
  • Status changed from assigned to new

comment:11 Changed 8 weeks ago by bmispelon

  • Easy pickings unset

Removing the "easy picking" flag per jacbo's comment.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from (none) to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.