Skip to content

Commit

Permalink
A Matrix column doesn't have the property value when the onSetValue i…
Browse files Browse the repository at this point in the history
…s implemented fix #8885
  • Loading branch information
andrewtelnov committed Oct 2, 2024
1 parent 74fe73f commit f460418
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/survey-core/src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo {
return this.getValue(obj);
}
public getValue(obj: any): any {
if (this.onGetValue) return this.onGetValue(obj);
if (this.onGetValue) {
obj = this.getOriginalObj(obj);
return this.onGetValue(obj);
}
if (this.serializationProperty && !!obj[this.serializationProperty])
return obj[this.serializationProperty].getJson();
return obj[this.name];
Expand All @@ -442,6 +445,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo {
}
public setValue(obj: any, value: any, jsonConv: JsonObject): void {
if (this.onSetValue) {
obj = this.getOriginalObj(obj);
this.onSetValue(obj, value, jsonConv);
} else {
if (this.serializationProperty && !!obj[this.serializationProperty])
Expand Down
39 changes: 39 additions & 0 deletions packages/survey-core/tests/jsonobjecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3376,3 +3376,42 @@ QUnit.test("Do fire JS unhandled exception on loading empty objects, Bug#8702",
const q5 = q4.detailPanel.getQuestionByName("q5");
assert.ok(q5, "#1");
});
QUnit.test("circular dependsOn, #8885", function (assert) {
let onSetValueObjType = "";
let onSettingValueObjType = "";
let onGetValueObjType = "";
Serializer.addProperty("question", { name: "prop1:boolean",
onSetValue: (obj, val) => {
onSetValueObjType = obj.getType();
obj.setPropertyValue("prop1", val);
},
onSettingValue: (obj, val) => {
onSettingValueObjType = obj.getType();
return val;
},
onGetValue: (obj) => {
onGetValueObjType = obj.getType();
return obj.getPropertyValue("prop1");
}
});
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1", prop1: true },
{ type: "matrixdynamic", name: "q2", columns: [
{ cellType: "text", name: "col1", prop1: true },
{ cellType: "text", name: "col2" },
{ name: "col3", prop1: true },
] }
]
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
assert.equal(q1.prop1, true, "text question");
assert.equal(q2.columns[0].prop1, true, "columns[0]");
assert.equal(q2.columns[1].prop1, false, "columns[1]");
assert.equal(q2.columns[2].prop1, true, "columns[2]");
assert.notEqual(onSetValueObjType, q2.columns[0].getType(), "object is not a column in onSetValue");
assert.notEqual(onSettingValueObjType, q2.columns[0].getType(), "object is not a column in onSettingValue");
assert.notEqual(onGetValueObjType, q2.columns[0].getType(), "object is not a column in onGetValueObjType");
Serializer.removeProperty("question", "prop1");
});

0 comments on commit f460418

Please sign in to comment.