Opened 5 years ago
Closed 5 years ago
#31170 closed Bug (needsinfo)
dismissRelatedLookupPopup doesn't trigger change event
Reported by: | J. David Ibáñez | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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(); }
Note:
See TracTickets
for help on using tickets.
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!)