Skip to content

Commit

Permalink
Remove jQuery from isMarkedForDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Dec 15, 2024
1 parent a2089a5 commit 8c6fe71
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions dist/client-side-validations.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions dist/client-side-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 4 additions & 2 deletions vendor/assets/javascripts/rails.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 8c6fe71

Please sign in to comment.