Skip to content

Commit

Permalink
Allow multiple Galleryfields per model.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuang committed Apr 22, 2024
1 parent 6d9d896 commit a7d57fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions galleryfield/templates/galleryfield/widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ <h4 class="modal-title" id="modalLabel">{% trans "Edit image" %}</h4>

{% 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 = {
Expand All @@ -306,6 +305,7 @@ <h4 class="modal-title" id="modalLabel">{% trans "Edit image" %}</h4>
singleFileUploads: true,
url: uploadURL,
type: 'POST',
hiddenFileInput: 'input#id_{{ name }}',
messages: {
maxFileSize: '{% trans "File is too big" %}',
minFileSize: '{% trans "File is too small" %}',
Expand Down Expand Up @@ -354,7 +354,7 @@ <h4 class="modal-title" id="modalLabel">{% trans "Edit image" %}</h4>

// 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);
}
});

Expand Down
5 changes: 1 addition & 4 deletions galleryfield/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7d57fb

Please sign in to comment.