Skip to content

Commit

Permalink
Carry forward with matrix/panel dynamic questions doesn't work on set…
Browse files Browse the repository at this point in the history
…ting survey.data fix #6734 (#6735)
  • Loading branch information
andrewtelnov authored Aug 17, 2023
1 parent 8f67dc4 commit ad689f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ export class Question extends SurveyElement<Question>
newValue = this.valueFromDataCallback(newValue);
}
this.setQuestionValue(this.valueFromData(newValue));
this.updateDependedQuestions();
this.updateIsAnswered();
}
updateCommentFromSurvey(newValue: any): any {
Expand Down
17 changes: 17 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,3 +1173,20 @@ QUnit.test("Check isUsingCarryForward on deleting matrix dynamic question", func
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Use carryForward with panel dynamic + update data on survey.data=data;", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choiceValuesFromQuestion: "q1-q2", choiceTextsFromQuestion: "q1-q3" },
{ type: "paneldynamic", name: "q1", panelCount: 2,
templateElements: [{ name: "q1-q1", type: "text" }, { name: "q1-q2", type: "text" }, { name: "q1-q3", type: "text" }]
}
] });
const q1 = <QuestionPanelDynamicModel>survey.getQuestionByName("q1");
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
survey.data = { q1: [{ "q1-q2": 1, "q1-q3": "Item 1" }, { "q1-q2": 2, "q1-q3": "Item 2" }] };
assert.equal(q2.visibleChoices.length, 2, "Create choices");
assert.equal(q2.visibleChoices[0].value, 1, "the first value is correct");
assert.equal(q2.visibleChoices[0].text, "Item 1", "the first text is correct");
assert.equal(q2.visibleChoices[1].value, 2, "the second value is correct");
assert.equal(q2.visibleChoices[1].text, "Item 2", "the second text is correct");
});

0 comments on commit ad689f6

Please sign in to comment.