Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15106 closed (duplicate)

label[for] attributes aren't updated when dynamically creating new inlines

Reported by: mk Owned by: nobody
Component: contrib.admin Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Processing for attributes too in inlines.js, addButton click handler fixes the problem.

Something like this:

diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js
index cf79023..d9dc9cb 100644
--- a/django/contrib/admin/media/js/inlines.js
+++ b/django/contrib/admin/media/js/inlines.js
@@ -71,6 +71,14 @@
                                    .end()
                                    .filter(function() {
                                        var el = $(this);
+                                       return el.attr("for") && el.attr("for").search(/__prefix__/) >= 0;
+                                   }).each(function() {
+                                       var el = $(this);
+                                       el.attr("for", el.attr("for").replace(/__prefix__/g, nextIndex));
+                                   })
+                                   .end()
+                                   .filter(function() {
+                                       var el = $(this);
                                        return el.attr("name") && el.attr("name").search(/__prefix__/) >= 0;
                                    }).each(function() {
                                        var el = $(this);

I'm not sure whether this is the best way to fix it, though. Processing a list of elements six times instead of once does not seem to make much sense to me.

This code isn't performance critical, though.

Attachments (1)

inlines.patch (769 bytes) - added by mk 3 years ago.

Download all attachments as: .zip

Change History (5)

Changed 3 years ago by mk

comment:1 Changed 3 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Could this be solved with an approach similar to the one proposed in #14830 ?

comment:2 Changed 3 years ago by mk

Both problems affect the inline javascript code, but the issues are different.

As I understand it, #14830 covers the problem that input[type=radio] elements are inserted too early into the DOM (before all IDs and NAMEs are changed). This ticket covers the problem that not all attributes which should be unique are updated properly, in this case the FOR attribute of label tags.

Maybe both bugs should be resolved at the same time, but that's not for me to decide.

comment:3 Changed 3 years ago by ramiro

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

Duplicate of #13674, it has a simpler patch attached, and the fix suggested by the OP there is very similar to the one proposed here.

comment:4 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.