From bb3f277ba5d22171a432aec0d02249cf59563db6 Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 20 Oct 2024 13:40:59 +0200 Subject: [PATCH] Extract js and css from select widgets to editable class attributes --- .../core/widgets/autocomplete_select.jinja | 6 ++++-- core/views/widgets/select.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/templates/core/widgets/autocomplete_select.jinja b/core/templates/core/widgets/autocomplete_select.jinja index ab91d766..a051c202 100644 --- a/core/templates/core/widgets/autocomplete_select.jinja +++ b/core/templates/core/widgets/autocomplete_select.jinja @@ -1,5 +1,7 @@ - -{% for css in statics.csss %} +{% for js in statics.js %} + +{% endfor %} +{% for css in statics.css %} {% endfor %} diff --git a/core/views/widgets/select.py b/core/views/widgets/select.py index a83ead7e..547e7f64 100644 --- a/core/views/widgets/select.py +++ b/core/views/widgets/select.py @@ -14,6 +14,14 @@ class AutoCompleteSelectMixin: schema: ModelSchema | None = None pk = "id" + js = [ + "webpack/core/components/ajax-select-index.ts", + ] + css = [ + "webpack/core/components/ajax-select-index.css", + "core/components/ajax-select.scss", + ] + def __init__(self, attrs=None, choices=()): if self.is_ajax: choices = () # Avoid computing anything when in ajax mode @@ -33,15 +41,8 @@ class AutoCompleteSelectMixin: context = super().get_context(name, value, attrs) context["component"] = self.component_name context["statics"] = { - "js": staticfiles_storage.url( - "webpack/core/components/ajax-select-index.ts" - ), - "csss": [ - staticfiles_storage.url( - "webpack/core/components/ajax-select-index.css" - ), - staticfiles_storage.url("core/components/ajax-select.scss"), - ], + "js": [staticfiles_storage.url(file) for file in self.js], + "css": [staticfiles_storage.url(file) for file in self.css], } if self.is_ajax: context["selected"] = [