Skip to content

Commit

Permalink
Merge branch 'fix/restore-jquery-file-uploads-js' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Dec 20, 2024
2 parents f579108 + 5ee95e2 commit af69697
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions hypha/static_src/javascript/file-uploads.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
document.addEventListener("DOMContentLoaded", function () {
// Initialize django-file-form
document.querySelectorAll("form").forEach(function (form) {
// Prevent initializing it multiple times and run it for forms
// that have a `form_id` field added by django-file-form.
if (!form.initUploadFieldsDone && form.querySelector("[name=form_id]")) {
init(form);
form.initUploadFieldsDone = true;
}
});
jQuery(function ($) {
// Initialize django-file-form
$("form")
.get()
.forEach(function (form) {
// Prevent initilising it multiple times and run it for forms
// that have a `form_id` field added by django-file-form.
if (
!form.initUploadFieldsDone &&
form.querySelector("[name=form_id]")
) {
init(form);
form.initUploadFieldsDone = true;
}
});

/**
* Initialize django-file-form for a form.
* @param {object} form The form to initialize.
*/
function init(form) {
if (document.querySelectorAll(".form__group--file").length) {
window.initUploadFields(form);
/**
* Initialize django-file-form for a form.
* @param {object} form The form to initialize.
*/
function init(form) {
if ($(".form__group--file").length) {
window.initUploadFields(form);

// Hide wrapper elements for hidden inputs added by django-file-form
document.querySelectorAll("input[type=hidden]").forEach(function (input) {
var closestFormGroup = input.closest(".form__group");
if (closestFormGroup) {
closestFormGroup.hidden = true;
// Hide wrapper elements for hidden inputs added by django-file-form
$("input[type=hidden]").closest(".form__group").hide();
}
});
}
}
});

0 comments on commit af69697

Please sign in to comment.