From b8f7d3f5ee295dd8fa766bb8c4a92eace5189352 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 12 Nov 2023 19:13:37 +0100 Subject: [PATCH] Fix #18792 - Avoid JS crashes when trying to remove rules of a field It was probably added by #16632 Signed-off-by: William Desportes --- js/src/table/change.js | 54 ++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/js/src/table/change.js b/js/src/table/change.js index af6beee5cd..26367bd1b6 100644 --- a/js/src/table/change.js +++ b/js/src/table/change.js @@ -308,30 +308,42 @@ function verificationsAfterFieldChange (urlField, multiEdit, theType) { $('#salt_' + target.id).remove(); } - // Remove possible blocking rules if the user changed functions - $('#' + target.id).rules('remove', 'validationFunctionForMd5'); - $('#' + target.id).rules('remove', 'validationFunctionForAesDesEncrypt'); - - if (target.value === 'MD5') { - $('#' + target.id).rules('add', { - validationFunctionForMd5: { - param: $thisInput, - depends: function () { - return checkForCheckbox(multiEdit); - } - } - }); + var couldFetchRules = false; + try { + // See: issue #18792 - In some weird cases the input goes away before it validates + // And it breaks jquery, this is a well known jquery bug with different trigger schemes + $('#' + target.id).rules(); + couldFetchRules = true; + } catch (error) { + console.log(error); } - if (target.value === 'DES_ENCRYPT' || target.value === 'AES_ENCRYPT') { - $('#' + target.id).rules('add', { - validationFunctionForAesDesEncrypt: { - param: $thisInput, - depends: function () { - return checkForCheckbox(multiEdit); + if (couldFetchRules) { + // Remove possible blocking rules if the user changed functions + $('#' + target.id).rules('remove', 'validationFunctionForMd5'); + $('#' + target.id).rules('remove', 'validationFunctionForAesDesEncrypt'); + + if (target.value === 'MD5') { + $('#' + target.id).rules('add', { + validationFunctionForMd5: { + param: $thisInput, + depends: function () { + return checkForCheckbox(multiEdit); + } } - } - }); + }); + } + + if (target.value === 'DES_ENCRYPT' || target.value === 'AES_ENCRYPT') { + $('#' + target.id).rules('add', { + validationFunctionForAesDesEncrypt: { + param: $thisInput, + depends: function () { + return checkForCheckbox(multiEdit); + } + } + }); + } } if (target.value === 'HEX' && theType.substring(0,3) === 'int') {