From beb3c830699f5b77769300060c8e92a2389f8977 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Wed, 15 Jan 2025 14:37:04 +0200 Subject: [PATCH] Rename the showMode property attribute fix #9291 --- packages/survey-core/src/itemvalue.ts | 5 +- packages/survey-core/src/jsonobject.ts | 25 ++++++++-- packages/survey-core/tests/jsonobjecttests.ts | 48 +++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/packages/survey-core/src/itemvalue.ts b/packages/survey-core/src/itemvalue.ts index fcd8a43af7..d41cf762e8 100644 --- a/packages/survey-core/src/itemvalue.ts +++ b/packages/survey-core/src/itemvalue.ts @@ -498,10 +498,9 @@ Serializer.addClass( name: "text", serializationProperty: "locText", }, - { name: "visibleIf:condition", showMode: "form" }, + { name: "visibleIf:condition", locationInTable: "detail" }, { - name: "enableIf:condition", - showMode: "form", + name: "enableIf:condition", locationInTable: "detail", visibleIf: (obj: ItemValue): boolean => { return !obj || obj.ownerPropertyName !== "rateValues"; }, diff --git a/packages/survey-core/src/jsonobject.ts b/packages/survey-core/src/jsonobject.ts index dfe715a659..85e43b6aae 100644 --- a/packages/survey-core/src/jsonobject.ts +++ b/packages/survey-core/src/jsonobject.ts @@ -223,6 +223,7 @@ export interface IJsonPropertyInfo { nextToProperty?: string; overridingProperty?: string; showMode?: string; + locationInTable?: string; maxLength?: number; maxValue?: any; minValue?: any; @@ -271,7 +272,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { "visibleIndex", "nextToProperty", "overridingProperty", - "showMode", + "locationInTable", "dependedProperties", "visibleIf", "enableIf", @@ -314,12 +315,12 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { public visibleIndex: number = -1; public nextToProperty: string; public overridingProperty: string; - public showMode: string; public availableInMatrixColumn: boolean; public maxLength: number = -1; public maxValue: any; public minValue: any; private dataListValue: Array; + private locationInTableValue: string; public layout: string; public version: string; public onSerializeValue: (obj: any) => any; @@ -362,8 +363,23 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo { this.className = this.typeValue.substring(0, this.typeValue.length - 2); } } + public get locationInTable(): string { + const res = this.locationInTableValue; + return !!res ? res : "both"; + } + public set locationInTable(val: string) { + if(val === "both") val = undefined; + this.locationInTableValue = val; + } + public get showMode(): string { + const res = this.locationInTable; + return res === "detail" ? "form" : (res === "column" ? "list" : ""); + } + public set showMode(val: string) { + this.locationInTable = val === "form" ? "detail" : (val === "list" ? "column" : undefined); + } public isArray = false; - public get isRequired() { + public get isRequired(): boolean { return this.isRequiredValue; } public set isRequired(val: boolean) { @@ -921,6 +937,9 @@ export class JsonMetadataClass { if (!Helpers.isValueEmpty(propInfo.showMode)) { prop.showMode = propInfo.showMode; } + if (!Helpers.isValueEmpty(propInfo.locationInTable)) { + prop.locationInTable = propInfo.locationInTable; + } if (!Helpers.isValueEmpty(propInfo.maxValue)) { prop.maxValue = propInfo.maxValue; } diff --git a/packages/survey-core/tests/jsonobjecttests.ts b/packages/survey-core/tests/jsonobjecttests.ts index 1d9a611c6e..41f6a1068a 100644 --- a/packages/survey-core/tests/jsonobjecttests.ts +++ b/packages/survey-core/tests/jsonobjecttests.ts @@ -3456,3 +3456,51 @@ QUnit.test("Page & Panel should have different title&description properties", fu assert.equal(panelTitle.placeholder, "panelT", "panel title unique"); assert.equal(panelDescription.placeholder, "panelD", "panel description unique"); }); +QUnit.test("property showMode -> displayMode, #9291", function (assert) { + const prop1 = Serializer.addProperty("question", { name: "prop1", showMode: "form" }); + const prop2 = Serializer.addProperty("question", { name: "prop2", locationInTable: "detail" }); + const prop3 = Serializer.addProperty("question", { name: "prop3" }); + const prop4 = Serializer.addProperty("question", { name: "prop4", showMode: "list" }); + const prop5 = Serializer.addProperty("question", { name: "prop5", locationInTable: "column" }); + const prop6 = Serializer.addProperty("question", { name: "prop6", locationInTable: "both" }); + + assert.equal(prop1.showMode, "form", "prop1.showMode"); + assert.equal(prop1.locationInTable, "detail", "prop1.locationInTable"); + assert.equal(prop2.showMode, "form", "prop2.showMode"); + assert.equal(prop2.locationInTable, "detail", "prop2.locationInTable"); + assert.equal(prop3.showMode, "", "prop3.showMode"); + assert.equal(prop3.locationInTable, "both", "prop3.locationInTable"); + assert.equal(prop4.showMode, "list", "prop4.showMode"); + assert.equal(prop4.locationInTable, "column", "prop4.locationInTable"); + assert.equal(prop5.showMode, "list", "prop5.showMode"); + assert.equal(prop5.locationInTable, "column", "prop5.locationInTable"); + assert.equal(prop6.showMode, "", "prop6.showMode"); + assert.equal(prop6.locationInTable, "both", "prop6.locationInTable"); + + prop1.showMode = ""; + assert.equal(prop1.showMode, "", "prop1.showMode, #2"); + assert.equal(prop1.locationInTable, "both", "prop1.locationInTable, #2"); + prop1.showMode = "list"; + assert.equal(prop1.showMode, "list", "prop1.showMode, #3"); + assert.equal(prop1.locationInTable, "column", "prop1.locationInTable, #3"); + prop1.showMode = "form"; + assert.equal(prop1.showMode, "form", "prop1.showMode, #4"); + assert.equal(prop1.locationInTable, "detail", "prop1.locationInTable, #4"); + + prop1.locationInTable = "both"; + assert.equal(prop1.showMode, "", "prop1.showMode, #5"); + assert.equal(prop1.locationInTable, "both", "prop1.locationInTable, #5"); + prop1.locationInTable = "column"; + assert.equal(prop1.showMode, "list", "prop1.showMode, #6"); + assert.equal(prop1.locationInTable, "column", "prop1.locationInTable, #6"); + prop1.locationInTable = "detail"; + assert.equal(prop1.showMode, "form", "prop1.showMode, #7"); + assert.equal(prop1.locationInTable, "detail", "prop1.locationInTable, #7"); + + Serializer.removeProperty("question", "prop1"); + Serializer.removeProperty("question", "prop2"); + Serializer.removeProperty("question", "prop3"); + Serializer.removeProperty("question", "prop4"); + Serializer.removeProperty("question", "prop5"); + Serializer.removeProperty("question", "prop6"); +}); \ No newline at end of file