Bug 37111: Add submit-form asset to OPAC assets

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Alexander Wagner <alexander.wagner@desy.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 6c56d3d90b)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Lucas Gass 2024-06-18 19:34:24 +00:00
parent 26c27a59e9
commit 15316dda98
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/* keep tidy */
$(document).ready(function () {
$(".submit-form-link").click(function (e) {
e.preventDefault();
let form_data = $(this).data();
let confirm_msg = form_data.confirmationMsg;
if (confirm_msg) {
let confirmation = confirm(confirm_msg);
if (!confirmation) {
return false;
}
delete form_data.confirmationMsg;
}
let the_form = $("<form/>");
if (form_data.method === "post") {
form_data.csrf_token = $('meta[name="csrf-token"]').attr("content");
}
the_form.attr("method", form_data.method);
the_form.attr("action", form_data.action);
delete form_data.method;
delete form_data.action;
$.each(form_data, function (key, value) {
the_form.append(
$("<input/>", {
type: "hidden",
name: key,
value: value,
})
);
});
$("body").append(the_form);
the_form.submit();
});
});