Skip to content

Commit

Permalink
Fix #292 -- Change admin widgets' JS media ordering (#295)
Browse files Browse the repository at this point in the history
Select2Mixin now loads admin/js/jquery.init.js, just like the AutocompleteMixin of Django Admin.

---------

Co-authored-by: Johannes Maron <[email protected]>
  • Loading branch information
mardukbp and codingjoe authored Aug 9, 2024
1 parent d87a5ad commit 50c488c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ class Select2AdminMixin:
def media(self):
css = {**AutocompleteMixin(None, None).media._css}
css["screen"].append("django_select2/django_select2.css")
js = [*Select2Mixin().media._js]
js.insert(
js.index("django_select2/django_select2.js"), "admin/js/jquery.init.js"
)
return forms.Media(
js=Select2Mixin().media._js,
js=js,
css=css,
)

Expand Down
1 change: 1 addition & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def test_media(self):
assert tuple(Select2AdminMixin().media._js) == (
"admin/js/vendor/select2/select2.full.min.js",
"admin/js/vendor/select2/i18n/en.js",
"admin/js/jquery.init.js",
"django_select2/django_select2.js",
)

Expand Down

0 comments on commit 50c488c

Please sign in to comment.