From 71e48348deb0a81a7be5dc1c90fc1f47b500d594 Mon Sep 17 00:00:00 2001
From: Eduardo Morales Alberti
 <12516-EduardoMoralesAlberti@users.noreply.drupalcode.org>
Date: Fri, 10 Feb 2023 09:14:39 -0500
Subject: [PATCH] Issue #3322946 by Eduardo Morales Alberti, dtarc,
 himanshu_jhaloya, joseph.olstad: Once is not well implemented

---
 clientside_validation_jquery/js/cv.jquery.ife.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/clientside_validation_jquery/js/cv.jquery.ife.js b/clientside_validation_jquery/js/cv.jquery.ife.js
index bdaf760..51dc967 100644
--- a/clientside_validation_jquery/js/cv.jquery.ife.js
+++ b/clientside_validation_jquery/js/cv.jquery.ife.js
@@ -5,7 +5,14 @@
 (function ($, once) {
   // Override clientside validation jquery validation options.
   // We do this to display the error markup same as in inline_form_errors.
-  once('cvjquery', 'document').forEach(element => element.on('cv-jquery-validate-options-update', function (event, options) {
+  // Using once can not use `window` or `document` directly.
+  if (!once('cvjquery', 'html').length) {
+    // Early return avoid changing the indentation
+    // for the rest of the code.
+    return;
+  }
+
+  $(document).on('cv-jquery-validate-options-update', function (event, options) {
     options.errorElement = 'strong';
     options.showErrors = function(errorMap, errorList) {
       // First remove all errors.
@@ -23,5 +30,5 @@
         }
       });
     };
-  }));
+  });
 })(jQuery, once);
-- 
GitLab