From 964e63ddbf6dd3d375c6bfc21ff46d54b9f54cb4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 16 Sep 2023 19:20:05 +0300 Subject: [PATCH] Pre-processing translation strings stop working in v1.9.106/107 fix #6967 (#6968) --- src/survey.ts | 16 ++++++++++------ tests/surveytests.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/survey.ts b/src/survey.ts index 406dbff454..bf0e8c7c8b 100644 --- a/src/survey.ts +++ b/src/survey.ts @@ -128,8 +128,6 @@ export class SurveyModel extends SurveyElementCore private variablesHash: HashTable = {}; private editingObjValue: Base; - private textPreProcessor: TextPreProcessor; - private timerModelValue: SurveyTimerModel; private navigationBarValue: ActionContainer; @@ -827,10 +825,6 @@ export class SurveyModel extends SurveyElementCore this.createLocalizableString("editText", this, false, true); this.createLocalizableString("questionTitleTemplate", this, true); - this.textPreProcessor = new TextPreProcessor(); - this.textPreProcessor.onProcess = (textValue: TextPreProcessorValue) => { - this.getProcessedTextValue(textValue); - }; this.timerModelValue = new SurveyTimerModel(this); this.timerModelValue.onTimer = (page: PageModel): void => { this.doTimer(page); @@ -6596,6 +6590,16 @@ export class SurveyModel extends SurveyElementCore res.hasAllValuesOnLastRun = this.textPreProcessor.hasAllValuesOnLastRun; return res; } + private textPreProcessorValue: TextPreProcessor; + private get textPreProcessor(): TextPreProcessor { + if(!this.textPreProcessorValue) { + this.textPreProcessorValue = new TextPreProcessor(); + this.textPreProcessorValue.onProcess = (textValue: TextPreProcessorValue) => { + this.getProcessedTextValue(textValue); + }; + } + return this.textPreProcessorValue; + } private processTextCore( text: string, returnDisplayValue: boolean, diff --git a/tests/surveytests.ts b/tests/surveytests.ts index edb175f0a2..32e4b3e723 100644 --- a/tests/surveytests.ts +++ b/tests/surveytests.ts @@ -17872,3 +17872,17 @@ QUnit.test("Test propertyValue() function", function (assert) { q2: [{ q2_q1_exp: "Q2_Q1" }], q3: [{ col1_exp: "Column 1" }] }, "propertyValue works correctly"); }); +QUnit.test("Error on pre-processing localizable string Bug#6967", function (assert) { + const prevVal = surveyLocalization.locales.en.completeText; + surveyLocalization.locales.en.completeText = "{q1}"; + const survey = new SurveyModel({ + elements: [ + { + type: "text", + name: "q1" + }] + }); + survey.data = { q1: 2 }; + assert.equal(survey.locCompleteText.renderedHtml, "2", "Preprocess correctly"); + surveyLocalization.locales.en.completeText = prevVal; +});