Skip to content

Allow select2_js to be list #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions django_select2/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,32 @@ class Select2Conf(AppConf):
It has set `select2_` as a default value, which you can change if needed.
"""

JS = "admin/js/vendor/select2/select2.full.min.js"
JS = ["admin/js/vendor/select2/select2.full.min.js"]
"""
The URI for the Select2 JS file. By default this points to version shipped with Django.

If you want to select the version of the JS library used, or want to serve it from
the local 'static' resources, add a line to your settings.py like so::

SELECT2_JS = 'assets/js/select2.min.js'
SELECT2_JS = ['assets/js/select2.min.js']

If you provide your own JS and would not like Django-Select2 to load any, change
this setting to a blank string like so::

SELECT2_JS = ''
SELECT2_JS = []

.. tip:: Change this setting to a local asset in your development environment to
develop without an Internet connection.
"""

CSS = "admin/css/vendor/select2/select2.min.css"
CSS = ["admin/css/vendor/select2/select2.min.css"]
"""
The URI for the Select2 CSS file. By default this points to version shipped with Django.

If you want to select the version of the library used, or want to serve it from
the local 'static' resources, add a line to your settings.py like so::

SELECT2_CSS = 'assets/css/select2.css'
SELECT2_CSS = ['assets/css/select2.css']

If you want to add more css (usually used in select2 themes), add a line
in settings.py like this::
Expand All @@ -93,7 +93,7 @@ class Select2Conf(AppConf):
If you provide your own CSS and would not like Django-Select2 to load any, change
this setting to a blank string like so::

SELECT2_CSS = ''
SELECT2_CSS = []

.. tip:: Change this setting to a local asset in your development environment to
develop without an Internet connection.
Expand Down
4 changes: 3 additions & 1 deletion django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ def media(self):
.. Note:: For more information visit
https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property
"""
select2_js = [settings.SELECT2_JS] if settings.SELECT2_JS else []
select2_js = settings.SELECT2_JS if settings.SELECT2_JS else []
select2_css = settings.SELECT2_CSS if settings.SELECT2_CSS else []

if isinstance(select2_js, str):
select2_js = [select2_js]
if isinstance(select2_css, str):
select2_css = [select2_css]

Expand Down