From 70abd8027edbfa75db867ad860779029e6464538 Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Thu, 11 Jan 2018 14:57:41 +0000 Subject: [PATCH] =?UTF-8?q?(Retrofit=20from=20trunk)=20Merged=20revision(s?= =?UTF-8?q?)=205192=20&=205193.=20r5192:=20N=C2=B01243=20Fix=20MUST=5FCHAN?= =?UTF-8?q?GE/MANDATORY=20checks=20on=20transition=20in=20the=20console=20?= =?UTF-8?q?on=20an=20HTML=20Attribute.=20r5193:=20Rollback=20modifications?= =?UTF-8?q?=20from=20r5192=20as=20it=20introduced=20a=20regression.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JS escaping and previous value comparison strategies are to be define before going further with this matter. SVN:2.4[5236] --- js/forms-json-utils.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/js/forms-json-utils.js b/js/forms-json-utils.js index a5bdec794a..81509cd508 100644 --- a/js/forms-json-utils.js +++ b/js/forms-json-utils.js @@ -245,9 +245,10 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue, origi return true; // Do not stop propagation ?? } -function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue) +function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue) { var bValid; + var sExplain = ''; var sTextContent; if ($('#'+sFieldId).attr('disabled')) @@ -277,31 +278,36 @@ function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue) } } } - - if (bMandatory && (sTextContent == '')) + + // 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) - { - 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; } } - ReportFieldValidationStatus(sFieldId, sFormId, bValid, ''); + ReportFieldValidationStatus(sFieldId, sFormId, bValid, sExplain); // We need to check periodically as CKEditor doesn't trigger our events. More details in UIHTMLEditorWidget::Display() @ line 92 setTimeout(function(){ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue);}, 500);