Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#15106 closed (duplicate)

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

Reported by: Matthias Kestenholz 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: no UI/UX: no

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 Matthias Kestenholz 13 years ago.

Download all attachments as: .zip

Change History (5)

by Matthias Kestenholz, 13 years ago

Attachment: inlines.patch added

comment:1 by Ramiro Morales, 13 years ago

Triage Stage: UnreviewedAccepted

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

comment:2 by Matthias Kestenholz, 13 years ago

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 by Ramiro Morales, 13 years ago

Resolution: duplicate
Status: newclosed

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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top