[Django] #31170: dismissRelatedLookupPopup doesn't trigger change event

43 views
Skip to first unread message

Django

unread,
Jan 16, 2020, 5:22:29 AM1/16/20
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-----------------------------------------+------------------------
Reporter: jdavid | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
I've a custom form with a field using ForeignKeyRawIdWidget (field1), and
a select box (field2) dependent on field1.
I've some JS listening for change events in field1, when this happens
field2 is updated.

The problem is, when field1 is chosen using the popup the change event is
not triggered, so field2 is not updated.

This is easy to fix:


{{{
--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -49,6 +49,9 @@
} else {
document.getElementById(name).value = chosenId;
}
+ var evt = document.createEvent("HTMLEvents");
+ evt.initEvent("change", false, true);
+ elem.dispatchEvent(evt);
win.close();
}
}}}

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

Django

unread,
Jan 16, 2020, 5:31:06 AM1/16/20
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+--------------------------------------
Reporter: J. David Ibáñez | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => needsinfo


Comment:

Can you put a minimal project/page together showing this, and why you
can't attach your own listener and such?
(It's a bit difficult to see exactly what's going on just from that
diff...)
Thanks.

(I'm going to close for now as needsinfo. Please re-open when you have an
example. Thanks!)

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:1>

Django

unread,
Dec 17, 2024, 10:44:01 AM12/17/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+--------------------------------------
Reporter: J. David Ibáñez | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Harm Geerts):

Example https://github.com/Urth/django-ticket-31170
Create a super user, runserver and navigate to
http://127.0.0.1:8000/ticket_31170/article/add/

- Select a user with the RelatedLookupPopup looking glass button.
- Observe that nothing happens
- Change the user id yourself
- Observe the javascript alert

The desired behavior is implemented in `dismissAddRelatedObjectPopup`
which uses the same approach as the patch below.

{{{
diff --git
a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
index 74d17bfc3e..16699da785 100644
--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -55,8 +55,10 @@
if (elem.classList.contains('vManyToManyRawIdAdminField') &&
elem.value) {
elem.value += ',' + chosenId;
} else {
- document.getElementById(name).value = chosenId;
+ elem.value = chosenId;
}
+ // Trigger a change event to update related fields if required.
+ $(elem).trigger('change');
const index = relatedWindows.indexOf(win);
if (index > -1) {
relatedWindows.splice(index, 1);
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:2>

Django

unread,
Dec 17, 2024, 10:44:29 AM12/17/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+--------------------------------------
Reporter: J. David Ibáñez | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Harm Geerts):

* resolution: needsinfo =>
* status: closed => new
* version: 3.0 => dev

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:3>

Django

unread,
Dec 17, 2024, 10:57:38 AM12/17/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+--------------------------------------
Reporter: J. David Ibáñez | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Harm Geerts):

* version: dev => 3.0

Comment:

The issue was observed in 3.0, but I tested on dev.
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:4>

Django

unread,
Dec 18, 2024, 3:32:34 AM12/18/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+------------------------------------
Reporter: J. David Ibáñez | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
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: 0
---------------------------------+------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

Thank you for the test project Harm!
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:5>

Django

unread,
Dec 23, 2024, 2:25:53 PM12/23/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+------------------------------------
Reporter: J. David Ibáñez | Owner: lumi808
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
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: 0
---------------------------------+------------------------------------
Changes (by lumi808):

* owner: nobody => lumi808
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:6>

Django

unread,
Dec 24, 2024, 6:37:46 PM12/24/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+----------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat Makym
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Kairat Makym):

* has_patch: 0 => 1
* stage: Accepted => Unreviewed

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:7>

Django

unread,
Dec 25, 2024, 6:04:16 AM12/25/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Kairat Makym):

* stage: Unreviewed => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:8>

Django

unread,
Dec 25, 2024, 11:01:46 AM12/25/24
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
---------------------------------+----------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat Makym
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Jacob Walls):

* stage: Ready for checkin => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:9>

Django

unread,
Feb 18, 2025, 3:54:44 AM2/18/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:10>

Django

unread,
Feb 18, 2025, 4:34:25 AM2/18/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"91bebf1adb43561b54bac18e76224759dc70acb3" 91bebf1a]:
{{{#!CommitTicketReference repository=""
revision="91bebf1adb43561b54bac18e76224759dc70acb3"
Refs #31170 -- Added JavaScript tests for RelatedObjectLookups.js.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:11>

Django

unread,
Feb 18, 2025, 4:34:25 AM2/18/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"51398f8bd568a6324a8cafe20c068d0974913ad5" 51398f8b]:
{{{#!CommitTicketReference repository=""
revision="51398f8bd568a6324a8cafe20c068d0974913ad5"
Fixed #31170 -- Added change event trigger to dismissRelatedLookupPopup.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:12>

Django

unread,
Feb 18, 2025, 4:37:04 AM2/18/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"b0d497ada04bb6dccdfc2c4072744de391b7d3b7" b0d497a]:
{{{#!CommitTicketReference repository=""
revision="b0d497ada04bb6dccdfc2c4072744de391b7d3b7"
[5.2.x] Fixed #31170 -- Added change event trigger to
dismissRelatedLookupPopup.

Backport of 51398f8bd568a6324a8cafe20c068d0974913ad5 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:14>

Django

unread,
Feb 18, 2025, 4:37:06 AM2/18/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"7cf6a34cb2f3ff973e1321818186e45da900ff3a" 7cf6a34]:
{{{#!CommitTicketReference repository=""
revision="7cf6a34cb2f3ff973e1321818186e45da900ff3a"
[5.2.x] Refs #31170 -- Added JavaScript tests for RelatedObjectLookups.js.

Backport of 91bebf1adb43561b54bac18e76224759dc70acb3 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:13>

Django

unread,
Apr 1, 2025, 12:52:40 PM4/1/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by GitHub <noreply@…>):

In [changeset:"a245604277eb9edeba234dacf199890766462709" a245604]:
{{{#!CommitTicketReference repository=""
revision="a245604277eb9edeba234dacf199890766462709"
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 <m...@feinheit.ch>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:15>

Django

unread,
Apr 1, 2025, 12:55:54 PM4/1/25
to django-...@googlegroups.com
#31170: dismissRelatedLookupPopup doesn't trigger change event
-------------------------------------+-------------------------------------
Reporter: J. David Ibáñez | Owner: Kairat
| Makym
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"614be94957d6b17a8b3d051204e62559e1f089e6" 614be949]:
{{{#!CommitTicketReference repository=""
revision="614be94957d6b17a8b3d051204e62559e1f089e6"
[5.2.x] 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 <m...@feinheit.ch>

Backport of a245604277eb9edeba234dacf199890766462709 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31170#comment:16>
Reply all
Reply to author
Forward
0 new messages