Steps to reproduce the problem illustrated in the screenshot:
1. Create a {{{myblog}}} django project and a {{{blog}}} app.
2. Specify this {{{models.py}}} in the {{{blog}}} app:
{{{
from django.db import models
class BlogPost(models.Model):
content = models.TextField()
class Author(models.Model):
blog_post = models.ForeignKey(BlogPost, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
birthday = models.DateField(blank=True)
}}}
3. Specify this {{{admin.py}}}:
{{{
from django.contrib import admin
from . import models
class AuthorInline(admin.StackedInline):
model = models.Author
extra = 1
fieldsets = [
("Essential", {"fields": ("name",), "classes": ("collapse",)}),
("Advanced", {"fields": ("birthday",), "classes": ("collapse",)}),
]
@admin.register(models.BlogPost)
class BlogPostAdmin(admin.ModelAdmin):
inlines = [AuthorInline]
}}}
4. Add the {{{blog}}} app to {{{INSTALLED_APPS}}}, makemigrations,
migrate, createsuperuser, runserver.
5. Visit /admin/, login, go to "Blog posts", click on "Add new blog post",
then click on "Add new Author".
Result: The "Show" links on the new Author form don't work. See the
screenshot for more information.
--
Ticket URL: <https://code.djangoproject.com/ticket/30459>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "Selection_011.png" added.
Screenshot that illustrates the problem
Comment (by ruchit2801):
I could not reproduce this. See this screencast, both the links in my case
works properly. Pardon me if did something wrong, or misunderstood
something
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:1>
* Attachment "Screenshot 2019-05-09 at 12.47.34 AM.png" added.
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
OK, yes. Thanks for the report
This a regression in ba83378a7762c51be235b521aa5b48233d6c6c82, which was
part of Django v2.2.
(Reproduced at af5ec222ccd24e81f9fec6c34836a4e503e7ccf7)
The change from using [http://api.jquery.com/on/ jQuery's `on()`] did not
correctly account for the _delegation_ of event handlers.
Instead of attaching directly to the `a.collapse-toggle` elements (which
in this case do not exist in the DOM at when the listener is added) we
should attach to a parent element and filter events by the event target
class (as jQuery does/did for us).
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:2>
Comment (by Claude Paroz):
Are you sure that's the regression? Looking at the code, jQuery was also
directly attaching the handler to the `a` link (`$("fieldset.collapse a
.collapse-toggle").on('click', function(ev) {`).
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:3>
Comment (by Carlton Gibson):
Hey Claude.
I've tested on both 2.1 and 2.2. It works on 2.1, but not 2.2.
I (manually) bisected to the referenced commit, using this history view:
https://github.com/django/django/commits/master/django/contrib/admin/static/admin/js
It works at a5f139236f930df06ae0642507530ca98081e2a9#diff-
6f61a4571a97f023bafaedabcadd5f54 but fails at the next commit
ba83378a7762c51be235b521aa5b48233d6c6c82#diff-
6f61a4571a97f023bafaedabcadd5f54 — so I pinned it to that. (It's the only
change that looks relevant.)
You are right about the `on()` call though... 🤔
I was going to write a `js_tests` case to reproduce this. I'll then be
able to actually `git bisect`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:4>
Comment (by Claude Paroz):
Carlton, did you progress with the test or was it just an intention?
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:5>
Comment (by Claude Paroz):
I think this has something to do with the jQuery `clone(true)` method
(called from `inlines.js`) which is supposed to also copy events from the
original DOM element. It may be that it doesn't work with vanilla JS
events? To be investigated.
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:6>
Comment (by Carlton Gibson):
Hey Claude.
No, I haven’t got there yet. (Worked out where to put it but not actually
written it.)
My plan was to look at it next week (2019 WK20). If you beat me to it,
that is fine. 🙂
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:7>
* has_patch: 0 => 1
* needs_tests: 0 => 1
Comment:
A [https://github.com/django/django/pull/11353 suggested fix], without
tests though.
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:8>
Comment (by Carlton Gibson):
Awesome. Thanks Claude! I'm happy to add the test in the week. Super.
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:9>
* status: new => assigned
* owner: nobody => Carlton Gibson
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:10>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:11>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e286987a27271c8ee7eb6e4d4332b563c4e6094b" e286987a]:
{{{
#!CommitTicketReference repository=""
revision="e286987a27271c8ee7eb6e4d4332b563c4e6094b"
Fixed #30459 -- Delegated hide/show JS toggle to parent div.
Co-authored-by: Carlton Gibson <carlton...@noumenal.es>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:12>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"34a357d519a6ff37516c963181af912f776ea80d" 34a357d5]:
{{{
#!CommitTicketReference repository=""
revision="34a357d519a6ff37516c963181af912f776ea80d"
[2.2.x] Fixed #30459 -- Delegated hide/show JS toggle to parent div.
Co-authored-by: Carlton Gibson <carlton...@noumenal.es>
Backport of e286987a27271c8ee7eb6e4d4332b563c4e6094b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30459#comment:13>