diff options
| author | nessita <124304+nessita@users.noreply.github.com> | 2025-04-01 13:52:22 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-01 13:52:22 -0300 |
| commit | a245604277eb9edeba234dacf199890766462709 (patch) | |
| tree | 0a4cf8adcbd4df4ca8c71b722d965476c725a9dd | |
| parent | a0fb35eb726f1a04eaa1b47b8de191fafe55a0ab (diff) | |
Fixed #36284, Refs #31170 -- Ensured related lookup popups are closed properly.
In the admin, when selecting related objects via the helpers defined in
`RelatedObjectLookups.js`, the `dismissRelatedLookupPopup` function was
attempting to access `window.relatedWindows`, which does not exist in
real execution, causing related lookup popups to remain open.
This change ensures that this code correctly accesses the module-local
`relatedWindows` by explicitly assigning it to `window.relatedWindows`.
Regression in 91bebf1adb43561b54bac18e76224759dc70acb3.
Thanks Matthias Kestenholz for the report, the fix ideas, and testing.
Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
| -rw-r--r-- | django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js | 5 | ||||
| -rw-r--r-- | js_tests/admin/RelatedObjectLookups.test.js | 1 |
2 files changed, 3 insertions, 3 deletions
diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 5395386087..1fc03c6232 100644 --- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/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 a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js index 722aa7ae7b..0d71d88f2a 100644 --- a/js_tests/admin/RelatedObjectLookups.test.js +++ b/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 || []; } }); |
