From 191aee752fbca19a1c53371f85ef303368513995 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Tue, 5 Sep 2023 14:33:37 +0300 Subject: [PATCH] Fix issue with has default value for localization strings --- src/base.ts | 2 ++ src/localizablestring.ts | 2 +- tests/basetests.ts | 16 ++++++++++++++-- tests/surveyserializationtests.ts | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/base.ts b/src/base.ts index 852280c7ea..bf88876b11 100644 --- a/src/base.ts +++ b/src/base.ts @@ -485,6 +485,8 @@ export class Base { if(!prop || prop.isCustom && this.isCreating) return undefined; const dValue = prop.defaultValue; if (!this.isPropertyEmpty(dValue) && !Array.isArray(dValue)) return dValue; + const locStr = this.localizableStrings ? this.localizableStrings[name] : undefined; + if(locStr && locStr.localizationName) return this.getLocalizationString(locStr.localizationName); if (prop.type == "boolean" || prop.type == "switch") return false; if (prop.isCustom && !!prop.onGetValue) return prop.onGetValue(this); return undefined; diff --git a/src/localizablestring.ts b/src/localizablestring.ts index c394b05fc5..21e62c65e8 100644 --- a/src/localizablestring.ts +++ b/src/localizablestring.ts @@ -199,7 +199,7 @@ export class LocalizableString implements ILocalizableString { var oldValue = this.onStrChanged && loc === curLoc ? this.pureText : undefined; delete (this).htmlValues[loc]; if (this.isValueEmpty(value)) { - if (this.getValue(loc)) this.deleteValue(loc); + this.deleteValue(loc); } else { if (typeof value === "string") { if (this.canRemoveLocValue(loc, value)) { diff --git a/tests/basetests.ts b/tests/basetests.ts index 158e4ff3a7..13ca512998 100644 --- a/tests/basetests.ts +++ b/tests/basetests.ts @@ -5,7 +5,7 @@ import { property, Serializer } from "../src/jsonobject"; import { SurveyModel } from "../src/survey"; import { Action } from "../src/actions/action"; import { findParentByClassNames } from "../src/utils/utils"; -import { QuestionTextModel } from "../src/question_text"; +import { QuestionDropdownModel } from "../src/question_dropdown"; export default QUnit.module("Base"); @@ -736,7 +736,7 @@ QUnit.test("Subscribe localizable property", function (assert) { assert.equal(updaterCallCount1, 2, "update called - localizable value"); }); QUnit.test("base.hasDefaultPropertyValue, base.getDefaultPropertyValue and base.resetPropertyValue()", function (assert) { - const question = new QuestionTextModel("q1"); + const question = new QuestionDropdownModel("q1"); assert.equal(question.hasDefaultPropertyValue("width"), false, "question.width has no default value"); assert.notOk(question.getDefaultPropertyValue("width"), "question.width default value is undefined"); question.width = "200px"; @@ -753,6 +753,18 @@ QUnit.test("base.hasDefaultPropertyValue, base.getDefaultPropertyValue and base. assert.strictEqual(question.minWidth, "", "minWidth property value is empty string"); question.resetPropertyValue("minWidth"); assert.equal(question.minWidth, "300px", "minWidth property value is reset, #2"); + + assert.equal(question.hasDefaultPropertyValue("placeholder"), true, "question.placeholder has default value"); + assert.equal(question.getDefaultPropertyValue("placeholder"), "Select...", "question.placeholder default value"); + assert.equal(question.placeholder, "Select...", "question.placeholder value"); + question.placeholder = "abc"; + assert.equal(question.placeholder, "abc", "placeholder property is set to 200px"); + question.resetPropertyValue("placeholder"); + assert.equal(question.placeholder, "Select...", "placeholder property value is reset, #1"); + question.placeholder = ""; + assert.strictEqual(question.placeholder, "", "placeholder property value is empty string"); + question.resetPropertyValue("placeholder"); + assert.equal(question.placeholder, "Select...", "placeholder property value is reset, #2"); }); QUnit.test("base.resetPropertyValue() for localization string", function (assert) { const survey = new SurveyModel(); diff --git a/tests/surveyserializationtests.ts b/tests/surveyserializationtests.ts index 7c8cb09514..ea44ead3bb 100644 --- a/tests/surveyserializationtests.ts +++ b/tests/surveyserializationtests.ts @@ -737,6 +737,10 @@ QUnit.test("Allow to save empty string for localization strings", function (asse assert.equal(q1.placeholder, "test", "set value for placeholder, #3"); q1.locPlaceholder.clearLocale(); assert.equal(q1.placeholder, "Select...", "ClearLocale for placeholder"); + q1.placeholder = ""; + assert.equal(q1.placeholder, "", "placeholder is empty"); + q1.locPlaceholder.clearLocale(); + assert.equal(q1.placeholder, "Select...", "ClearLocale for placeholder, #2"); }); QUnit.test("Allow to save empty string for trings with default value", function (assert) { const q = new QuestionTextModel("q1");