From c5f5ed924ebabaa3ee4abf4852bfb76322776ee2 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 15 Dec 2024 20:30:13 +0100 Subject: [PATCH] Refactor isMarkedForDestroy for clarity --- dist/client-side-validations.esm.js | 5 +++-- dist/client-side-validations.js | 5 +++-- src/index.js | 6 ++++-- vendor/assets/javascripts/rails.validations.js | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/dist/client-side-validations.esm.js b/dist/client-side-validations.esm.js index 990a14ef..101a015d 100644 --- a/dist/client-side-validations.esm.js +++ b/dist/client-side-validations.esm.js @@ -661,8 +661,9 @@ var executeValidators = function executeValidators(validatorFunctions, $element, return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - if ($element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) { - var destroyInputName = $element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]'); + var elementName = $element.attr('name'); + if (/\[([^\]]*?)\]$/.test(elementName)) { + var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { return true; } diff --git a/dist/client-side-validations.js b/dist/client-side-validations.js index 86a45d1e..d8ac4f04 100644 --- a/dist/client-side-validations.js +++ b/dist/client-side-validations.js @@ -665,8 +665,9 @@ return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - if ($element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) { - var destroyInputName = $element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]'); + var elementName = $element.attr('name'); + if (/\[([^\]]*?)\]$/.test(elementName)) { + var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { return true; } diff --git a/src/index.js b/src/index.js index 0a810e65..7d306855 100644 --- a/src/index.js +++ b/src/index.js @@ -168,8 +168,10 @@ const executeValidators = (validatorFunctions, $element, validators) => { } const isMarkedForDestroy = ($element) => { - if ($element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) { - const destroyInputName = $element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]') + const elementName = $element.attr('name') + + if (/\[([^\]]*?)\]$/.test(elementName)) { + const destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]') if (jQuery(`input[name="${destroyInputName}"]`).val() === '1') { return true diff --git a/vendor/assets/javascripts/rails.validations.js b/vendor/assets/javascripts/rails.validations.js index 86a45d1e..d8ac4f04 100644 --- a/vendor/assets/javascripts/rails.validations.js +++ b/vendor/assets/javascripts/rails.validations.js @@ -665,8 +665,9 @@ return true; }; var isMarkedForDestroy = function isMarkedForDestroy($element) { - if ($element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) { - var destroyInputName = $element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]'); + var elementName = $element.attr('name'); + if (/\[([^\]]*?)\]$/.test(elementName)) { + var destroyInputName = elementName.replace(/\[([^\]]*?)\]$/, '[_destroy]'); if (jQuery("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') { return true; }