#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 <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/01070193d54a4572-0a15c40b-e2fe-40f6-a20b-ef231fd18559-000000%40eu-central-1.amazonses.com.