#36284: Related lookup popup doesn't close after selecting an existing item
-------------------------------------+-------------------------------------
     Reporter:  Matthias Kestenholz  |                    Owner:  Natalia
                                     |  Bidart
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.admin        |                  Version:  5.2
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
  RelatedObjectLookups               |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Matthias Kestenholz):

 Yes, that does fix the issue both when running browser tests and also when
 using the `raw_id_fields` popup in the administration interface.

 I also tested the following patch which replaces `window.relatedWindows`
 usage in the admin JavaScript with `relatedWindows` and it works as well
 and seems a tiny little bit cleaner:

 {{{
 diff --git
 i/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
 w/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
 index 5395386087..0522ba60b5 100644
 --- i/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
 +++ w/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
 @@ -58,9 +58,9 @@
              elem.value = chosenId;
          }
          $(elem).trigger('change');
 -        const index = window.relatedWindows.indexOf(win);
 +        const index = relatedWindows.indexOf(win);
          if (index > -1) {
 -            window.relatedWindows.splice(index, 1);
 +            relatedWindows.splice(index, 1);
          }
          win.close();
      }
 @@ -206,6 +206,7 @@
      window.dismissChangeRelatedObjectPopup =
 dismissChangeRelatedObjectPopup;
      window.dismissDeleteRelatedObjectPopup =
 dismissDeleteRelatedObjectPopup;
      window.dismissChildPopups = dismissChildPopups;
 +    window.relatedWindows = relatedWindows;

      // Kept for backward compatibility
      window.showAddAnotherPopup = showRelatedObjectPopup;
 diff --git i/js_tests/admin/RelatedObjectLookups.test.js
 w/js_tests/admin/RelatedObjectLookups.test.js
 index 722aa7ae7b..0d71d88f2a 100644
 --- i/js_tests/admin/RelatedObjectLookups.test.js
 +++ w/js_tests/admin/RelatedObjectLookups.test.js
 @@ -8,7 +8,6 @@ QUnit.module('admin.RelatedObjectLookups', {
              <input type="text" id="test_id" name="test" />
              <input type="text" id="many_test_id" name="many_test"
 class="vManyToManyRawIdAdminField" />
          `);
 -        window.relatedWindows = window.relatedWindows || [];
      }
  });

 }}}

 The additional hunks in `dismissRelatedLookupPopup` change the code to
 more closely resemble all other functions which also access
 `relatedWindows` directly and not through the `window` object.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36284#comment:6>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070195f1ed8276-b758eb19-6dc0-4f64-a6d4-22c397211052-000000%40eu-central-1.amazonses.com.

Reply via email to