From a7d57fbd205da837d316fa439fdbfa045bafeac6 Mon Sep 17 00:00:00 2001 From: dzhuang Date: Mon, 22 Apr 2024 22:54:14 +0800 Subject: [PATCH] Allow multiple Galleryfields per model. --- galleryfield/templates/galleryfield/widget.html | 8 ++++---- galleryfield/widgets.py | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/galleryfield/templates/galleryfield/widget.html b/galleryfield/templates/galleryfield/widget.html index 5236eca..c0789fc 100644 --- a/galleryfield/templates/galleryfield/widget.html +++ b/galleryfield/templates/galleryfield/widget.html @@ -293,9 +293,8 @@ {% endif %} - $('.gallery-widget').each(function () { - const that = $(this), - $fileupload = that, + $(function () { + const $fileupload = $("#id-{{ name }}-gallery-widget"), fileInput = $('#{{ name }}-files'), uploadURL = fileInput.data('action'), sortableOptions = { @@ -306,6 +305,7 @@ singleFileUploads: true, url: uploadURL, type: 'POST', + hiddenFileInput: 'input#id_{{ name }}', messages: { maxFileSize: '{% trans "File is too big" %}', minFileSize: '{% trans "File is too small" %}', @@ -354,7 +354,7 @@ // disable change alert when submit form. if (typeof before_submit !== 'undefined') { - that.closest("form").on("submit", before_submit); + $fileupload.closest("form").on("submit", before_submit); } }); diff --git a/galleryfield/widgets.py b/galleryfield/widgets.py index 041579b..b3c5fc2 100644 --- a/galleryfield/widgets.py +++ b/galleryfield/widgets.py @@ -345,10 +345,7 @@ def get_stringfied_jquery_file_upload_ui_options(self): _width, _height = self.thumbnail_size.split("x") ui_options.update( {"previewMaxWidth": int(_width), - "previewMaxHeight": int(_height), - - # This is used as a CSS selector to fine the input field - "hiddenFileInput": f".{conf.FILES_FIELD_CLASS_NAME}", + "previewMaxHeight": int(_height) }) # Compatibility with Bootstrap 4 and 5