Skip to content

Commit 81f4347

Browse files
Learnpath: Fix duplicate LP items insertion on multi-click save - refs #5744
1 parent 7ae29fe commit 81f4347

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

public/main/lp/learnpath.class.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5728,7 +5728,27 @@ public function displayDocumentForm($action = 'add', $lpItem = null)
57285728

57295729
$form->addButtonSave(get_lang('Save'), 'submit_button');
57305730

5731-
return $form->returnForm();
5731+
$script = '<script>
5732+
document.addEventListener("DOMContentLoaded", function () {
5733+
var form = document.getElementById("form") || document.forms["form"];
5734+
if (!form) return;
5735+
form.addEventListener("submit", function (e) {
5736+
var btn = form.querySelector("button[name=submit_button], input[name=submit_button]");
5737+
if (!btn) return;
5738+
// async disable to avoid interfering with possible sync handlers triggered on submit
5739+
setTimeout(function () {
5740+
try {
5741+
btn.disabled = true;
5742+
if (btn.classList) btn.classList.add("disabled");
5743+
} catch (err) {
5744+
// silent
5745+
}
5746+
}, 0);
5747+
}, { once: true }); // once: true to disable only on the first submit
5748+
});
5749+
</script>';
5750+
5751+
return $form->returnForm() . $script;
57325752
}
57335753

57345754
/**

0 commit comments

Comments
 (0)