From e3b9263252479f2cf87192cdc8dbce7f5a403864 Mon Sep 17 00:00:00 2001 From: Maryna Balioura Date: Fri, 18 Sep 2026 15:09:35 +0200 Subject: [PATCH] fix(forms): clear stale validation errors on resubmit Previously the old markup and errors="true" attributes stayed in the DOM until the server responded to a resubmitted form, so a fixed value still showed the earlier error while saving was in progress. Clear them on turbo:submit-start instead of waiting for the response. --- .../export/html/_static/action_button_guard.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/strictdoc/export/html/_static/action_button_guard.js b/strictdoc/export/html/_static/action_button_guard.js index df3bd7b443..0846f6c17b 100644 --- a/strictdoc/export/html/_static/action_button_guard.js +++ b/strictdoc/export/html/_static/action_button_guard.js @@ -37,4 +37,17 @@ document.addEventListener('turbo:submit-end', resetPending); document.addEventListener('turbo:frame-render', resetPending); + // Clear stale validation errors from a form as soon as it is resubmitted, + // rather than leaving them on screen until the new response arrives. + document.addEventListener('turbo:submit-start', function (event) { + const form = event.target; + if (!(form instanceof HTMLFormElement)) return; + form.querySelectorAll('sdoc-form-error').forEach(function (errorEl) { + errorEl.remove(); + }); + form.querySelectorAll('[errors]').forEach(function (fieldEl) { + fieldEl.removeAttribute('errors'); + }); + }); + })();