admin inline form id attribute numbering order and uniqueness is lost
|Reported by:||m0nonoke||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Inline forms that are added using the "Add another ..." button created by contrib/admin/media/js/inlines.js lose their id attribute ordering and uniqueness if they are deleted out of reverse order.
To demonstrate the effect take the following steps:
- Create an admin form eg. MyAdmin with a tabular inline form eg. MyInline.
- Add 3 or more inline forms using the "Add another MyInline button"
- The HTML for the formset looks something like <tr id="myinline_set-0" class="dynamic-myinline_ser row1"> where myinline_set is the prefix. For 4 forms the ids are therefore myinline_set-0, myinline_set-1, myinline_set-2, myinline_set-3.
- Delete the second form using the delete link. The ids are now myinline_set-0, myinline_set-2, myinline_set-3.
- Add another inline using the "Add another MyInline button". The ids now show The ids are now myinline_set-0, myinline_set-2, myinline_set-3, myinline_set-3.
It looks like the problem occurs because of the way the id is computed in contrib/admin/media/js/inlines.js.
# contrib/admin/media/js/inlines.js Line 59-62 59 row.removeClass(options.emptyCssClass) 60 .addClass(options.formCssClass) 61 .attr("id", options.prefix + "-" + nextIndex) 62 .insertBefore($(template));
nextIndex is just the TOTAL_FORMS value of the management form plus one. The solution would involve resetting the values for all inline forms.
Change History (8)
comment:1 Changed 6 years ago by m0nonoke
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 6 years ago by julien
- Has patch set
- Keywords sprintdec2010 added
- Triage Stage changed from Unreviewed to Accepted