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; +});