(Retrofit from trunk) Merged revision(s) 5192 & 5193.

r5192: N°1243 Fix MUST_CHANGE/MANDATORY checks on transition in the console on an HTML Attribute.
r5193: Rollback modifications from r5192 as it introduced a regression.

JS escaping and previous value comparison strategies are to be define before going further with this matter.

SVN:2.4[5236]
This commit is contained in:
Guillaume Lajarige
2018-01-11 14:57:41 +00:00
parent 4c6e6ffc9c
commit 70abd8027e

View File

@@ -245,9 +245,10 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue, origi
return true; // Do not stop propagation ?? return true; // Do not stop propagation ??
} }
function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue) function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue)
{ {
var bValid; var bValid;
var sExplain = '';
var sTextContent; var sTextContent;
if ($('#'+sFieldId).attr('disabled')) 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) ? $('<div></div>').html(originalValue) : undefined;
var sTextOriginalContents = (oFormattedOriginalContents !== undefined) ? oFormattedOriginalContents.text() : undefined;
if (bMandatory && (sTextContent == nullValue))
{ {
bValid = false; bValid = false;
sExplain = Dict.S('UI:ValueMustBeSet');
} }
else if ((sTextOriginalContents != undefined) && (sTextContent == sTextOriginalContents)) else if ((sTextOriginalContents != undefined) && (sTextContent == sTextOriginalContents))
{ {
bValid = false; bValid = false;
if (sTextOriginalContents == nullValue) if (sTextOriginalContents == nullValue)
{ {
sExplain = Dict.S('UI:ValueMustBeSet'); sExplain = Dict.S('UI:ValueMustBeSet');
} }
else 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. // 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'); sExplain = Dict.S('UI:ValueMustBeChanged');
} }
} }
else else
{ {
bValid = true; 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 // 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); setTimeout(function(){ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue);}, 500);