#33336 closed New feature (duplicate)
Widget.Media.JS ESM support
Reported by: | James Pic | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Currently, Django only renders widget JS media as scripts:
https://github.com/django/django/blob/main/django/forms/widgets.py#L82
It would be great to support type=module right there.
Change History (4)
comment:1 by , 3 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 3 years ago
And that's how the decision has been made to not support ESM in Django. There goes a very convenient feature for modern web development!
comment:3 by , 3 years ago
Replying to James Pic:
And that's how the decision has been made to not support ESM in Django. There goes a very convenient feature for modern web development!
I wouldn't say that. There are other media types that we could support but the first step to opening this door is to handle Media
subclasses in Django. It would be straightforward to support JavaScript modules (or others) with #9357, e.g.:
class MyMedia(Media): def __init__(self, media=None, css=None, js=None, js_modules=None): self.js_modules = js_modules super().__init__(media, css, js) def render_js_modules(self): return format_html(...)
You can start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think. We can always reopen this ticket after reaching a consensus that JavaScript modules should be treated and handled separately.
comment:4 by , 3 years ago
Thank you Mariusz! I'm not on the mailing list, and I'm not trying to override the Media class but just to use the modern script attributes, meanwhile, if anyone's looking for an example they can use there's one here I just made up: https://yourlabs.io/oss/djhacker/-/commit/0861a15f9d4a57f9841a3e07688e0832fde8d9fc
It also allows for async, defer, etc all script attributes: https://developer.mozilla.org/fr/docs/Web/HTML/Element/script
As far as I'm aware we can close is as a duplicate of more general ticket #9357.