Code

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14303 closed (fixed)

admin inline form id attribute numbering order and uniqueness is lost

Reported by: m0nonoke Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: inline javascript, sprintdec2010
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

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:

  1. Create an admin form eg. MyAdmin with a tabular inline form eg. MyInline.
  1. Add 3 or more inline forms using the "Add another MyInline button"
  1. 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.
  1. Delete the second form using the delete link. The ids are now myinline_set-0, myinline_set-2, myinline_set-3.
  1. 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.

Attachments (1)

14303_inline_ids.diff (7.2 KB) - added by julien 3 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by m0nonoke

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by julien

  • Has patch set
  • Keywords javascript, sprintdec2010 added; javascript removed
  • Triage Stage changed from Unreviewed to Accepted

I confirm this is a bug. This can be fixed by keeping nextIndex static and not refreshing it with the TOTAL_FORMS value each time. See patch attached.

Changed 3 years ago by julien

comment:3 Changed 3 years ago by julien

See #13674 for a related (but different) bug.

comment:4 Changed 3 years ago by julien

  • Triage Stage changed from Accepted to Ready for checkin

RFC'ing my own patch but hopefully this is a simple-enough fix to allow me to do that :)

comment:5 Changed 3 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

In [15422]:

Fixed #14303 -- Ensure that the ids created for new inlines are unique after interstitial deletions have occurred. Thanks to m0nonoke for the report, and Julien Phalip for the patch.

comment:6 Changed 3 years ago by russellm

In [15423]:

[1.2.X] Fixed #14303 -- Ensure that the ids created for new inlines are unique after interstitial deletions have occurred. Thanks to m0nonoke for the report, and Julien Phalip for the patch.

Backport of r15422 from trunk.

comment:7 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.