From e6914543391b0acde333f6edbf6e80e7ff484884 Mon Sep 17 00:00:00 2001 From: acognet Date: Fri, 15 Apr 2022 10:00:08 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B05002=20-=20memory=20leak=20after=20objec?= =?UTF-8?q?t=20creation=20in=20popup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/forms-json-utils.js | 106 ++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 60 deletions(-) diff --git a/js/forms-json-utils.js b/js/forms-json-utils.js index 0eec9508d..57c97e91b 100644 --- a/js/forms-json-utils.js +++ b/js/forms-json-utils.js @@ -300,75 +300,61 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue, origi function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue) { - var bValid; - var sExplain = ''; - var sTextContent; + if ($('#'+sFieldId).size() > 0) { + var bValid; + var sExplain = ''; + var sTextContent; - if ($('#'+sFieldId).prop('disabled')) - { - bValid = true; // disabled fields are not checked - } - else - { - // Get the contents without the tags - var oFormattedContents = $("#cke_"+sFieldId+" iframe"); - if (oFormattedContents.length == 0) - { - var oSourceContents = $("#cke_"+sFieldId+" textarea.cke_source"); - sTextContent = oSourceContents.val(); - } - else - { - sTextContent = oFormattedContents.contents().find("body").text(); - - if (sTextContent == '') - { - // No plain text, maybe there is just an image... - var oImg = oFormattedContents.contents().find("body img"); - if (oImg.length != 0) - { - sTextContent = 'image'; + if ($('#'+sFieldId).prop('disabled')) { + bValid = true; // disabled fields are not checked + } else { + // Get the contents without the tags + var oFormattedContents = $("#cke_"+sFieldId+" iframe"); + if (oFormattedContents.length == 0) { + var oSourceContents = $("#cke_"+sFieldId+" textarea.cke_source"); + sTextContent = oSourceContents.val(); + } else { + sTextContent = oFormattedContents.contents().find("body").text(); + + if (sTextContent == '') { + // No plain text, maybe there is just an image... + var oImg = oFormattedContents.contents().find("body img"); + if (oImg.length != 0) { + sTextContent = 'image'; + } } } - } - // Get the original value without the tags - var oFormattedOriginalContents = (originalValue !== undefined) ? $('
').html(originalValue) : undefined; - var sTextOriginalContents = (oFormattedOriginalContents !== undefined) ? oFormattedOriginalContents.text() : undefined; - - if (bMandatory && (sTextContent == nullValue)) - { - bValid = false; - sExplain = Dict.S('UI:ValueMustBeSet'); - } - else if ((sTextOriginalContents != undefined) && (sTextContent == sTextOriginalContents)) - { - bValid = false; - if (sTextOriginalContents == nullValue) - { + // Get the original value without the tags + var oFormattedOriginalContents = (originalValue !== undefined) ? $('
').html(originalValue) : undefined; + var sTextOriginalContents = (oFormattedOriginalContents !== undefined) ? oFormattedOriginalContents.text() : undefined; + + if (bMandatory && (sTextContent == nullValue)) { + bValid = false; sExplain = Dict.S('UI:ValueMustBeSet'); - } - else - { - // Note: value change check is not working well yet as the HTML to Text conversion is not exactly the same when done from the PHP value or the CKEditor value. - sExplain = Dict.S('UI:ValueMustBeChanged'); + } else if ((sTextOriginalContents != undefined) && (sTextContent == sTextOriginalContents)) { + bValid = false; + if (sTextOriginalContents == nullValue) { + sExplain = Dict.S('UI:ValueMustBeSet'); + } else { + // Note: value change check is not working well yet as the HTML to Text conversion is not exactly the same when done from the PHP value or the CKEditor value. + sExplain = Dict.S('UI:ValueMustBeChanged'); + } + } else { + bValid = true; } } - else - { - bValid = true; + + ReportFieldValidationStatus(sFieldId, sFormId, bValid, sExplain); + + if ($('#'+sFieldId).data('timeout_validate') == undefined) { + // We need to check periodically as CKEditor doesn't trigger our events. More details in UIHTMLEditorWidget::Display() @ line 92 + var iTimeoutValidate = setInterval(function () { + ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue); + }, 500); + $('#'+sFieldId).data('timeout_validate', iTimeoutValidate); } } - - ReportFieldValidationStatus(sFieldId, sFormId, bValid, sExplain); - - if ($('#'+sFieldId).data('timeout_validate') == undefined) { - // We need to check periodically as CKEditor doesn't trigger our events. More details in UIHTMLEditorWidget::Display() @ line 92 - var iTimeoutValidate = setInterval(function () { - ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue); - }, 500); - $('#'+sFieldId).data('timeout_validate', iTimeoutValidate); - } } /*