From 8c6fe710f79b91964c1c362c07f86cc5d003b315 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 15 Dec 2024 21:02:57 +0100 Subject: [PATCH 1/2] Remove jQuery from `isMarkedForDestroy` --- dist/client-side-validations.esm.js | 6 ++++-- dist/client-side-validations.js | 6 ++++-- src/index.js | 6 ++++-- vendor/assets/javascripts/rails.validations.js | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/client-side-validations.esm.js b/dist/client-side-validations.esm.js index 101a015d..9e96e6e4 100644 --- a/dist/client-side-validations.esm.js +++ b/dist/client-side-validations.esm.js @@ -661,10 +661,12 @@ var executeValidators = function executeValidators(validatorFunctions, $element, return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - var elementName = $element.attr('name'); + var element = $element[0]; + var elementName = element.name; if (/\[([^\]]*?)\]$/.test(elementName)) { var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); - if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { + var destroyInputElement = document.querySelector("input[name=\"".concat(destroyInputName, "\"]")); + if (destroyInputElement && destroyInputElement.value === '1') { return true; } } diff --git a/dist/client-side-validations.js b/dist/client-side-validations.js index d8ac4f04..ebf191fe 100644 --- a/dist/client-side-validations.js +++ b/dist/client-side-validations.js @@ -665,10 +665,12 @@ return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - var elementName = $element.attr('name'); + var element = $element[0]; + var elementName = element.name; if (/\[([^\]]*?)\]$/.test(elementName)) { var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); - if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { + var destroyInputElement = document.querySelector("input[name=\"".concat(destroyInputName, "\"]")); + if (destroyInputElement && destroyInputElement.value === '1') { return true; } } diff --git a/src/index.js b/src/index.js index 7d306855..c7b36985 100644 --- a/src/index.js +++ b/src/index.js @@ -168,12 +168,14 @@ const executeValidators = (validatorFunctions, $element, validators) => { } const isMarkedForDestroy = ($element) => { - const elementName = $element.attr('name') + const element = $element[0] + const elementName = element.name if (/\[([^\]]*?)\]$/.test(elementName)) { const destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]') + const destroyInputElement = document.querySelector(`input[name="${destroyInputName}"]`) - if (jQuery(`input[name="${destroyInputName}"]`).val() === '1') { + if (destroyInputElement && destroyInputElement.value === '1') { return true } } diff --git a/vendor/assets/javascripts/rails.validations.js b/vendor/assets/javascripts/rails.validations.js index d8ac4f04..ebf191fe 100644 --- a/vendor/assets/javascripts/rails.validations.js +++ b/vendor/assets/javascripts/rails.validations.js @@ -665,10 +665,12 @@ return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - var elementName = $element.attr('name'); + var element = $element[0]; + var elementName = element.name; if (/\[([^\]]*?)\]$/.test(elementName)) { var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); - if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { + var destroyInputElement = document.querySelector("input[name=\"".concat(destroyInputName, "\"]")); + if (destroyInputElement && destroyInputElement.value === '1') { return true; } } From fa2bbd2fe0eff8d0dcd8c0ed43aff4151a1326e7 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 15 Dec 2024 21:05:53 +0100 Subject: [PATCH 2/2] Remove some jQuery from `executeAllValidators` `element.dataset` and `$element.data` are not the same thing --- dist/client-side-validations.esm.js | 3 ++- dist/client-side-validations.js | 3 ++- src/index.js | 3 ++- vendor/assets/javascripts/rails.validations.js | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dist/client-side-validations.esm.js b/dist/client-side-validations.esm.js index 9e96e6e4..3088dfd0 100644 --- a/dist/client-side-validations.esm.js +++ b/dist/client-side-validations.esm.js @@ -673,7 +673,8 @@ var isMarkedForDestroy = function isMarkedForDestroy($element) { return false; }; var executeAllValidators = function executeAllValidators($element, validators) { - if ($element.data('changed') === false || $element.prop('disabled')) { + var element = $element[0]; + if ($element.data('changed') === false || element.disabled) { return; } $element.data('changed', false); diff --git a/dist/client-side-validations.js b/dist/client-side-validations.js index ebf191fe..2ce97c4b 100644 --- a/dist/client-side-validations.js +++ b/dist/client-side-validations.js @@ -677,7 +677,8 @@ return false; }; var executeAllValidators = function executeAllValidators($element, validators) { - if ($element.data('changed') === false || $element.prop('disabled')) { + var element = $element[0]; + if ($element.data('changed') === false || element.disabled) { return; } $element.data('changed', false); diff --git a/src/index.js b/src/index.js index c7b36985..fe99561d 100644 --- a/src/index.js +++ b/src/index.js @@ -184,7 +184,8 @@ const isMarkedForDestroy = ($element) => { } const executeAllValidators = ($element, validators) => { - if ($element.data('changed') === false || $element.prop('disabled')) { + const element = $element[0] + if ($element.data('changed') === false || element.disabled) { return } diff --git a/vendor/assets/javascripts/rails.validations.js b/vendor/assets/javascripts/rails.validations.js index ebf191fe..2ce97c4b 100644 --- a/vendor/assets/javascripts/rails.validations.js +++ b/vendor/assets/javascripts/rails.validations.js @@ -677,7 +677,8 @@ return false; }; var executeAllValidators = function executeAllValidators($element, validators) { - if ($element.data('changed') === false || $element.prop('disabled')) { + var element = $element[0]; + if ($element.data('changed') === false || element.disabled) { return; } $element.data('changed', false);