#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)
Change History (5)
by , 14 years ago
Attachment: | inlines.patch added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 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 , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → 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.
Could this be solved with an approach similar to the one proposed in #14830 ?