Skip to content

Commit 0b9ae1f

Browse files
committed
Dynamic Panel - The panel count bindings setting is not saved to a survey JSON definition fix #6743 (#6748)
1 parent 9e79b89 commit 0b9ae1f

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

packages/survey-creator-core/src/property-grid/bindings.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ export class PropertyGridEditorBindings extends PropertyGridEditor {
3030
public onCreated(obj: Base, question: QuestionCompositeModel, prop: JsonObjectProperty, options: ISurveyCreatorOptions) {
3131
question.contentPanel.fromJSON({ elements: this.getQuestions(obj, options) });
3232
question.valueFromDataCallback = (value: any): any => {
33-
if(!value && obj.bindings.getNames().length > 0) {
34-
const result: { [index: string]: any } = {};
35-
for(const bindingName of obj.bindings.getNames()) {
36-
result[bindingName] = obj.bindings.getValueNameByPropertyName(bindingName);
33+
const keys = obj.bindings.getNames();
34+
const result: { [index: string]: any } = {};
35+
if(keys.length > 0) {
36+
for(const key of keys) {
37+
result[key] = !!value ? value[key] : obj.bindings.getValueNameByPropertyName(key);
3738
}
38-
return result;
3939
}
40-
return value;
40+
return result;
4141
};
4242
}
4343
private getQuestions(obj: Base, options: ISurveyCreatorOptions): Array<object> {

packages/survey-creator-core/tests/property-grid/property-grid.tests.ts

+22
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,28 @@ test("bindings property editor", () => {
810810
q.value = "q3";
811811
expect(matrix.bindings.getValueNameByPropertyName("rowCount")).toEqual("q3");
812812
});
813+
test("bindings property editor, store in JSON, Bug#6743", () => {
814+
const survey = new SurveyModel({
815+
elements: [
816+
{ type: "matrixdynamic", name: "q1" },
817+
{ type: "text", name: "q2" }
818+
]
819+
});
820+
const matrix = <QuestionMatrixDynamicModel>survey.getQuestionByName("q1");
821+
const propertyGrid = new PropertyGridModelTester(matrix);
822+
const bindingsQuestion = <QuestionCompositeModel>(
823+
propertyGrid.survey.getQuestionByName("bindings")
824+
);
825+
expect(bindingsQuestion).toBeTruthy();
826+
expect(bindingsQuestion.getType()).toEqual("propertygrid_bindings");
827+
expect(bindingsQuestion.contentPanel.questions).toHaveLength(1);
828+
const q = bindingsQuestion.contentPanel.questions[0];
829+
expect(q.name).toEqual("rowCount");
830+
q.value = "q2";
831+
expect(matrix.bindings.getValueNameByPropertyName("rowCount")).toEqual("q2");
832+
expect(matrix.toJSON()).toEqual({ name: "q1", bindings: { rowCount: "q2" } });
833+
expect(survey.getQuestionByName("q2").toJSON()).toEqual({ name: "q2" });
834+
});
813835

814836
test("Dynamic panel 'Panel count' binding property editor", () => {
815837
const survey = new SurveyModel({

0 commit comments

Comments
 (0)