Skip to content

Commit

Permalink
Multi-Select and Dynamic Matrix - Introduce an option to serialize a … (
Browse files Browse the repository at this point in the history
#9081)

* 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
  • Loading branch information
andrewtelnov authored Nov 21, 2024
1 parent 602b384 commit b1b8aec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/survey-core/src/localizablestring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down
3 changes: 3 additions & 0 deletions packages/survey-core/src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/survey-core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ export var settings = {
serialization: {
itemValueSerializeAsObject: false,
itemValueSerializeDisplayText: false,
localizableStringSerializeAsObject: false
localizableStringSerializeAsObject: false,
matrixDropdownColumnSerializeTitle: false
},

//#region serialization section, Obsolete properties
Expand Down
14 changes: 14 additions & 0 deletions packages/survey-core/tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
});

0 comments on commit b1b8aec

Please sign in to comment.