Skip to content

Commit

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

0 comments on commit a2089a5

Please sign in to comment.