[Django] #35277: Issue with the new "formset:added" event

7 views
Skip to first unread message

Django

unread,
Mar 6, 2024, 5:49:38 PM3/6/24
to django-...@googlegroups.com
#35277: Issue with the new "formset:added" event
------------------------------------------------+------------------------
Reporter: meesterguyman | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/35277>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 6, 2024, 11:50:22 PM3/6/24
to django-...@googlegroups.com
#35277: Issue with the new "formset:added" event
-------------------------------------+-------------------------------------
Reporter: meesterguyman | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Claude Paroz (added)
* resolution: => invalid
* status: new => closed

Comment:

This is an intended change (eabc22f919e6c1774842e628400b87ac56c47bce) that
it [https://docs.djangoproject.com/en/stable/ref/contrib/admin/javascript
/#inline-form-events documented] and mentioned in
[https://docs.djangoproject.com/en/stable/releases/4.1/#miscellaneous
release notes], so revert is not an option. Also, it's explicitly
documented that:
> ''"For the `formset:added` event, `event.target` **is the newly added
row.**"''
--
Ticket URL: <https://code.djangoproject.com/ticket/35277#comment:1>
Reply all
Reply to author
Forward
0 new messages