From b1b8aec048a57491a17d2ef437381edb05554a0f Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 21 Nov 2024 19:41:52 +0000 Subject: [PATCH] =?UTF-8?q?Multi-Select=20and=20Dynamic=20Matrix=20-=20Int?= =?UTF-8?q?roduce=20an=20option=20to=20serialize=20a=20=E2=80=A6=20(#9081)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Multi-Select and Dynamic Matrix - Introduce an option to serialize a column's name and title even if they are identical fix #9007 * Rename columnSerializeTitle to matrixDropdownColumnSerializeTitle --- packages/survey-core/src/localizablestring.ts | 9 ++++++++- .../src/question_matrixdropdowncolumn.ts | 3 +++ packages/survey-core/src/settings.ts | 3 ++- .../tests/question_matrixdropdownbasetests.ts | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/survey-core/src/localizablestring.ts b/packages/survey-core/src/localizablestring.ts index a93f3556b9..067d8b8f6e 100644 --- a/packages/survey-core/src/localizablestring.ts +++ b/packages/survey-core/src/localizablestring.ts @@ -60,6 +60,7 @@ export class LocalizableString implements ILocalizableString { } public onGetTextCallback: (str: string) => string; public storeDefaultText: boolean; + public serializeCallBackText: boolean; public onGetLocalizationTextCallback: (str: string) => string; public onStrChanged: (oldValue: string, newValue: string) => void; public onSearchChanged: () => void; @@ -280,7 +281,13 @@ export class LocalizableString implements ILocalizableString { public getJson(): any { if (!!this.sharedData) return this.sharedData.getJson(); const keys = this.getValuesKeys(); - if (keys.length == 0) return null; + if (keys.length == 0) { + if(this.serializeCallBackText) { + const text = this.calcText(); + if(!!text) return text; + } + return null; + } if ( keys.length == 1 && keys[0] == settings.localization.defaultLocaleName && diff --git a/packages/survey-core/src/question_matrixdropdowncolumn.ts b/packages/survey-core/src/question_matrixdropdowncolumn.ts index 3464189c79..553ccf0eb9 100644 --- a/packages/survey-core/src/question_matrixdropdowncolumn.ts +++ b/packages/survey-core/src/question_matrixdropdowncolumn.ts @@ -728,6 +728,9 @@ export class MatrixDropdownColumn extends Base } else { this.templateQuestion.locTitle.strChanged(); } + if(settings.serialization.matrixDropdownColumnSerializeTitle) { + this.templateQuestion.locTitle.serializeCallBackText = true; + } this.templateQuestion.onPropertyChanged.add((sender, options) => { this.propertyValueChanged( options.name, diff --git a/packages/survey-core/src/settings.ts b/packages/survey-core/src/settings.ts index 2c3fa97286..c56a052465 100644 --- a/packages/survey-core/src/settings.ts +++ b/packages/survey-core/src/settings.ts @@ -213,7 +213,8 @@ export var settings = { serialization: { itemValueSerializeAsObject: false, itemValueSerializeDisplayText: false, - localizableStringSerializeAsObject: false + localizableStringSerializeAsObject: false, + matrixDropdownColumnSerializeTitle: false }, //#region serialization section, Obsolete properties diff --git a/packages/survey-core/tests/question_matrixdropdownbasetests.ts b/packages/survey-core/tests/question_matrixdropdownbasetests.ts index 0c05abc250..eb94cbd32a 100644 --- a/packages/survey-core/tests/question_matrixdropdownbasetests.ts +++ b/packages/survey-core/tests/question_matrixdropdownbasetests.ts @@ -9,6 +9,7 @@ import { Helpers } from "../src/helpers"; import { QuestionMatrixDropdownModel } from "../src/question_matrixdropdown"; import { QuestionCheckboxModel } from "../src/question_checkbox"; import { ItemValue } from "../src/itemvalue"; +import { settings } from "../src/settings"; export * from "../src/localization/german"; export default QUnit.module("Survey_QuestionMatrixDropdownBase"); @@ -1842,3 +1843,16 @@ QUnit.test("isQuestion answered & design time", function (assert) { assert.strictEqual(rows[1].cells[0].question.isAnswered, false, "[1, 0]"); assert.strictEqual(rows[1].cells[1].question.isAnswered, false, "[1, 1]"); }); +QUnit.test("Serialize empty column title, #9007", function (assert) { + settings.serialization.matrixDropdownColumnSerializeTitle = true; + + const matrix = new QuestionMatrixDropdownModel("q1"); + matrix.addColumn("col1"); + matrix.addColumn("col2", "Column2"); + assert.deepEqual(matrix.toJSON(), { + name: "q1", + columns: [{ name: "col1", title: "col1" }, { name: "col2", title: "Column2" }] + }, "Serialize empty title"); + + settings.serialization.matrixDropdownColumnSerializeTitle = false; +});