#34789: `filter_horizontal` duplicates entries in "Chosen" column after 
instance is
added via in another field using the "plus" JS action
-------------------------------+------------------------------------
     Reporter:  devin13cox     |                    Owner:  (none)
         Type:  Bug            |                   Status:  assigned
    Component:  contrib.admin  |                  Version:  4.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  1              |                    UI/UX:  1
-------------------------------+------------------------------------

Comment (by yokeshwaran1):

 Hi David,
 Im new to this repo,  so I appreciate any guidance or feedback u can
 offer.

 Regardin issue with filter_horizontal "Chosen" column.  From the
 discussion, I think about a solution which will not continuously
 blacklisting ancestors

 1. Adding a data attribute like data-context to select elements during its
 render phase in the Django admin templates. So each select will have a
 more specific context about its purpose (eg. source, target, chosen etc.).

 2. Then modifying the query in RelatedObjectLookups.js to use this new
 data-context attribute, so our selector will become:

 {{{
 const selectsRelated = document.querySelectorAll(`[data-model-
 ref="${modelName}"][data-context="source"] select:not(.admin-
 autocomplete)`);
 }}}

 This approach will provide clear context for each select element which
 makes JavaScript logic more intentional. would this be a feasible,
 acceptable solution in ur opinion? I'm eager to hear ur thoughts & make
 any necessary adjustments. Once approach is approved, I'm interested in
 working on this ticket. Please let me know if that's possible.

 Replying to [comment:8 David Sanders]:
 > Replying to [ticket:34789 devin13cox]:
 > > My initial guess is that updating the query to not include the
 "Chosen" column in filter_horizontal fields would solve this issue
 (something like
 > > {{{
 > > const selectsRelated = document.querySelectorAll(`[data-model-
 ref="${modelName}"] div:not(.selector-chosen) > select:not(.admin-
 autocomplete)`);
 > > }}}
 >
 > That could work 👍 I'm just wondering though whether there's a better
 approach than to continuously blacklist ancestors as we come across these
 🤔

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a385f7189-4bb7f6d8-9b86-4a72-a313-61d625ed72f8-000000%40eu-central-1.amazonses.com.

Reply via email to