diff --git a/src/question_custom.ts b/src/question_custom.ts index 869ffbe363..760783fe28 100644 --- a/src/question_custom.ts +++ b/src/question_custom.ts @@ -780,14 +780,21 @@ export class QuestionCompositeModel extends QuestionCustomModelBase { allowNotifyValueChanged?: boolean ): any { if (this.settingNewValue) return; + this.settingNewValue = true; + if (!this.isEditingSurveyElement && !!this.contentPanel) { + const panelValue = this.contentPanel.getValue(); + if(!this.isTwoValueEquals(this.getValueCore(), panelValue)) { + this.setValueCore(panelValue); + } + } super.setValue(name, newValue, locNotification, allowNotifyValueChanged); - if (!this.contentPanel) return; - var q = this.contentPanel.getQuestionByName(name); - if (!!q && !this.isTwoValueEquals(newValue, q.value)) { - this.settingNewValue = true; - q.value = newValue; - this.settingNewValue = false; + if (!!this.contentPanel) { + var q = this.contentPanel.getQuestionByName(name); + if (!!q && !this.isTwoValueEquals(newValue, q.value)) { + q.value = newValue; + } } + this.settingNewValue = false; } public addConditionObjectsByContext( objects: Array, diff --git a/src/question_matrixdropdownbase.ts b/src/question_matrixdropdownbase.ts index 35732e06b0..43f6a2b885 100644 --- a/src/question_matrixdropdownbase.ts +++ b/src/question_matrixdropdownbase.ts @@ -409,7 +409,7 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner { this.updateQuestionsValue(name, newColumnValue, isComment); var newValue = this.value; var changedName = isComment ? name + settings.commentPrefix : name; - var changedValue = isComment ? this.getComment(name) : this.getValue(name); + var changedValue = newColumnValue; var changedQuestion = this.getQuestionByName(name); var changingValue = this.data.onRowChanging(this, changedName, newValue); if ( diff --git a/tests/question_customtests.ts b/tests/question_customtests.ts index 677ffd9152..267fade5c7 100644 --- a/tests/question_customtests.ts +++ b/tests/question_customtests.ts @@ -1711,3 +1711,48 @@ QUnit.test("Single: survey.questionsOnPageMode = `singlePage`", function (assert assert.equal(q.contentQuestion.value, 3, "content question value is correct"); ComponentCollection.Instance.clear(); }); +QUnit.test("Composite: in matrices cells", function (assert) { + var json = { + name: "customerinfo", + elementsJSON: [ + { type: "text", name: "firstName" }, + { type: "text", name: "lastName" }, + ], + }; + ComponentCollection.Instance.add(json); + var survey = new SurveyModel({ + elements: [{ + type: "matrixdynamic", + name: "matrix", + rowCount: 1, + columns: [ + { cellType: "customerinfo", name: "col1" }, + ] + }] + }); + const matrix = survey.getQuestionByName("matrix"); + let row = matrix.visibleRows[0]; + let q = row.cells[0].question; + assert.equal(q.getType(), "customerinfo", "The correct type is created"); + assert.equal(q.contentPanel.elements.length, 2, "There are two elements in panel"); + q.contentPanel.getQuestionByName("firstName").value = "Jon"; + q.contentPanel.getQuestionByName("lastName").value = "Snow"; + assert.deepEqual(q.value, { firstName: "Jon", lastName: "Snow" }, "Set value to composite question correctly"); + assert.deepEqual(row.value, { col1: { firstName: "Jon", lastName: "Snow" } }, "Row value is correct"); + assert.deepEqual(matrix.value, [{ col1: { firstName: "Jon", lastName: "Snow" } }], "Matrix value is correct"); + assert.deepEqual(survey.data, { matrix: [{ col1: { firstName: "Jon", lastName: "Snow" } }] }, "survey.data is correct"); + + survey.data = { matrix: [ + { col1: { firstName: "Jaime", lastName: "Lannister" } }, + { col1: { firstName: "Jon", lastName: "Snow" } }] }; + + row = matrix.visibleRows[0]; + q = row.cells[0].question; + assert.equal(q.contentPanel.getQuestionByName("firstName").value, "Jaime", "row 0, firstName"); + assert.equal(q.contentPanel.getQuestionByName("lastName").value, "Lannister", "row 0, lastname"); + row = matrix.visibleRows[1]; + q = row.cells[0].question; + assert.equal(q.contentPanel.getQuestionByName("firstName").value, "Jon", "row 1, firstName"); + assert.equal(q.contentPanel.getQuestionByName("lastName").value, "Snow", "row 1, lastname"); + ComponentCollection.Instance.clear(); +});