Skip to content

Commit

Permalink
Composite component can't be used in matrices cells fixed #4705 (#4706)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 11, 2022
1 parent eea2af7 commit d9856f4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/question_custom.ts
Expand Up @@ -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<IConditionObject>,
Expand Down
2 changes: 1 addition & 1 deletion src/question_matrixdropdownbase.ts
Expand Up @@ -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 (
Expand Down
45 changes: 45 additions & 0 deletions tests/question_customtests.ts
Expand Up @@ -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 = <QuestionMatrixDynamicModel>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();
});

0 comments on commit d9856f4

Please sign in to comment.