Opened 9 months ago
Closed 9 months ago
#35277 closed Cleanup/optimization (invalid)
Issue with the new "formset:added" event
Reported by: | Bryant Glisson | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Claude Paroz | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We have certain custom widgets that need to be initialized when a new form is added to an inline. Previously, this event was triggered by the following:
$(document).trigger("formset:added", [row, options.prefix]);
We could then use jQuery's "on" method to add whatever callbacks needed to be executed. Most importantly, the "row" that was added could be was passed to the callback, making it very easy to do what we needed to that particular row. In 5.0, this was eliminated, and we have the following code instead:
row.get(0).dispatchEvent(new CustomEvent("formset:added", { bubbles: true, detail: { formsetName: options.prefix } }));
Not sure what the rational for this change was, but would really appreciate if you all could at least include the "row" in the detail passed here, or preferably revert to the previous code.
Source is below:
https://github.com/django/django/blob/c4df2a77761a1ae392eb5c4803b5712803d5239f/django/contrib/admin/static/admin/js/inlines.js#L91C24-L91C37
This is an intended change (eabc22f919e6c1774842e628400b87ac56c47bce) that it documented and mentioned in release notes, so revert is not an option. Also, it's explicitly documented that: