Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore jQuery version of file-uploads.js #4300

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions hypha/static_src/javascript/file-uploads.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
document.addEventListener("DOMContentLoaded", function () {
jQuery(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;
}
});
$("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) {
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;
}
});
$("input[type=hidden]").closest(".form__group").hide();
}
}
});
Loading