Skip to content

Commit

Permalink
Merge pull request #9323 from surveyjs/api/3607-showmode-attribute
Browse files Browse the repository at this point in the history
Rename the showMode property attribute fix #9291
  • Loading branch information
andrewtelnov authored Jan 15, 2025
2 parents 1d4b340 + beb3c83 commit 3081a9e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/survey-core/src/itemvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
},
Expand Down
25 changes: 22 additions & 3 deletions packages/survey-core/src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface IJsonPropertyInfo {
nextToProperty?: string;
overridingProperty?: string;
showMode?: string;
locationInTable?: string;
maxLength?: number;
maxValue?: any;
minValue?: any;
Expand Down Expand Up @@ -271,7 +272,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo {
"visibleIndex",
"nextToProperty",
"overridingProperty",
"showMode",
"locationInTable",
"dependedProperties",
"visibleIf",
"enableIf",
Expand Down Expand Up @@ -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<string>;
private locationInTableValue: string;
public layout: string;
public version: string;
public onSerializeValue: (obj: any) => any;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
48 changes: 48 additions & 0 deletions packages/survey-core/tests/jsonobjecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

0 comments on commit 3081a9e

Please sign in to comment.