Export camperUploadForm function

I did not remember that the file was loaded as a module, so i have
to export it in order to use from the <script> in media.  That <script>
needs to be also a module and explicitly import the function; since it
is already loaded, the browser does not load the file again.
This commit is contained in:
jordi fita mas 2023-09-24 03:19:46 +02:00
parent 4aa74c0768
commit 233aacc2de
3 changed files with 9 additions and 3 deletions

View File

@ -113,7 +113,7 @@ ready(function () {
}
})
function camperUploadForm(el) {
export function camperUploadForm(el) {
const progress = el.querySelector('progress');
htmx.on(el, 'drop', function (evt) {
evt.preventDefault();

View File

@ -32,7 +32,10 @@
<progress value="0" max="100"></progress>
</footer>
</form>
<script>camperUploadForm(document.getElementById('mediaPickerUpload'))</script>
<script type="module">
import {camperUploadForm} from "/static/camper.js";
camperUploadForm(document.getElementById('mediaPickerUpload'));
</script>
<form action="/admin/media/field" method="get" data-hx-boost="true" data-hx-push-url="false">
{{ with .Field -}}
<input type="hidden" name="name" value="{{ .Name }}"/>

View File

@ -28,5 +28,8 @@
<progress value="0" max="100"></progress>
</footer>
</form>
<script>camperUploadForm(document.getElementById('mediaUpload'))</script>
<script type="module">
import {camperUploadForm} from "/static/camper.js";
camperUploadForm(document.getElementById('mediaUpload'));
</script>
{{- end }}