From a3a71a3f4f5b10f973e5d48ae874ac399de089f1 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 9 Sep 2024 21:23:20 +0200 Subject: [PATCH] =?UTF-8?q?Copi=C3=A9/coll=C3=A9=20notes:=20fix=20#990?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/saisie_notes.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/static/js/saisie_notes.js b/app/static/js/saisie_notes.js index 1a5eafdb3..98b9410c6 100644 --- a/app/static/js/saisie_notes.js +++ b/app/static/js/saisie_notes.js @@ -6,12 +6,7 @@ document.addEventListener("DOMContentLoaded", function () { input.addEventListener("input", function() { this.setAttribute("data-modified", "true"); }); - input.addEventListener("blur", function() { - if (this.getAttribute("data-modified") === "true" && this.value !== this.getAttribute("data-last-saved-value")) { - valid_note.call(this); - this.setAttribute("data-modified", "false"); // Reset the modified flag - } - }); + input.addEventListener("blur", input.addEventListener("blur", function(event){write_on_blur(event.currentTarget)} )); }); var formInputs = document.querySelectorAll("#formnotes input"); @@ -23,6 +18,13 @@ document.addEventListener("DOMContentLoaded", function () { masquerBtn.addEventListener("click", masquer_DEM); }); +function write_on_blur(elt) { + if (elt.getAttribute("data-modified") === "true" && elt.value !== elt.getAttribute("data-last-saved-value")) { + valid_note.call(elt); + elt.setAttribute("data-modified", "false"); // Reset the modified flag + } +} + function is_valid_note(v) { if (!v) return true; @@ -143,11 +145,10 @@ function change_history(e) { // Contribution S.L.: copier/coller des notes -function paste_text(e) { - var event = e.originalEvent; +function paste_text(event) { event.stopPropagation(); event.preventDefault(); - var clipb = e.originalEvent.clipboardData; + var clipb = event.clipboardData; var data = clipb.getData("Text"); var list = data.split(/\r\n|\r|\n|\t| /g); var currentInput = event.currentTarget; @@ -159,9 +160,11 @@ function paste_text(e) { if (!currentInput.disabled) { // skip DEM currentInput.value = list[i]; } - var evt = document.createEvent("HTMLEvents"); - evt.initEvent("blur", false, true); + // --- trigger blur + currentInput.setAttribute("data-modified", "true"); + var evt = new Event("blur", { bubbles: true, cancelable: true}); currentInput.dispatchEvent(evt); + // --- next input var sibbling = currentInput.parentElement.parentElement.nextElementSibling; while ( sibbling &&