Skip to content

Commit 1eceed0

Browse files
LuboZlubos.zlatohlavek
andauthored
triv: #24320 file upload field in modal content (#46)
* triv: #24320 file upload field in modal content * triv: #24320 file upload field in modal content * triv: #24320 file upload field in modal content * Update version --------- Co-authored-by: lubos.zlatohlavek <[email protected]>
1 parent 559df11 commit 1eceed0

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-smartbase-admin"
3-
version = "0.2.100"
3+
version = "0.2.101"
44
description = ""
55
authors = ["SmartBase <[email protected]>"]
66
readme = "README.md"

src/django_smartbase_admin/static/sb_admin/src/js/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ class Main {
4949
window.open(e.detail.url, e.detail?.target || '_blank')
5050
})
5151

52+
if(window.htmx){
53+
window.htmx.on("htmx:afterSwap", (detail) => {
54+
const requestEl = detail.detail.requestConfig.elt.closest('[hx-swap]')
55+
if(requestEl && requestEl.getAttribute('hx-swap') === "none") {
56+
// do not process afterSwap if none swap is performed
57+
// this should prevent double processing of afterSwap for first oob-swapped element
58+
// which in case of hx-swap=none is returned here in the detail.target
59+
return
60+
}
61+
this.initFileInputs(detail.target)
62+
this.initDropdowns(detail.target)
63+
})
64+
}
65+
5266
new Sidebar()
5367
this.datepicker = new Datepicker()
5468
this.range = new Range()

src/django_smartbase_admin/templates/sb_admin/partials/modal/modal_content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h3 class="text-dark-900 text-18 font-semibold leading-28">{% block modal_title
1616
</div>
1717
<div class="modal-body">
1818
{% block modal_body %}
19-
<form id="sb-admin-modal-form" hx-indicator=".sb-admin-modal-loading" hx-target="#sb-admin-modal" hx-post="{{ request.get_full_path }}" action="{{ request.get_full_path }}" method="post">
19+
<form id="sb-admin-modal-form" enctype="multipart/form-data" hx-indicator=".sb-admin-modal-loading" hx-target="#sb-admin-modal" hx-post="{{ request.get_full_path }}" action="{{ request.get_full_path }}" method="post">
2020
{% if form.errors %}
2121
<div class="alert bg-negative-50 border border-negative-100 text-negative-900 mb-24">
2222
<div class="flex">

0 commit comments

Comments
 (0)