Skip to content

Commit

Permalink
Change ranking value in composite component fix #7897 (#7898)
Browse files Browse the repository at this point in the history
* work for the #7897

* Fix unit test and the issue #7897

* Fix lint issue in the unit test #7897

---------

Co-authored-by: dmitrykurmanov <[email protected]>
  • Loading branch information
andrewtelnov and dmitry-kurmanov authored Feb 22, 2024
1 parent 8d34a9b commit 8e39f30
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,15 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
}
}
}
onSurveyValueChanged(newValue: any): void {
super.onSurveyValueChanged(newValue);
const val = !!newValue ? newValue : {};
if (!!this.contentPanel) {
this.contentPanel.questions.forEach(q => {
q.onSurveyValueChanged(val[q.getValueName()]);
});
}
}
getValue(name: string): any {
var val = this.value;
return !!val ? val[name] : null;
Expand Down
33 changes: 33 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2981,5 +2981,38 @@ QUnit.test("file question in composite component doesn't show preview in preview
assert.equal(file_q1.showPreviewContainer, true, "file_q1 #1");
assert.equal(file_q2.showPreviewContainer, true, "file_q2 #1");

ComponentCollection.Instance.clear();
});

QUnit.test("Composite + Ranking", function (assert) {
const json = {
"elements": [{
"name": "q_composite",
"type": "compostite_witn_ranking"
}]
};
const comp_json = {
name: "compostite_witn_ranking",
showInToolbox: false,
internal: true,
elementsJSON: [
{
name: "q_ranking",
type: "ranking",
selectToRankEnabled: true,
}
]
};
ComponentCollection.Instance.add(comp_json);

const survey = new SurveyModel(json);
const q_composite = survey.getQuestionByName("q_composite");
const q_ranking = q_composite.contentPanel.getQuestionByName("q_ranking");
q_ranking.choices = ["a", "b", "c", "d", "e"];
q_ranking.value = ["a", "b", "c"];

assert.equal(q_ranking.unRankingChoices.length, 2, "ranking value is correct (unrank list length) ['d', 'e']");
assert.equal(q_ranking.rankingChoices.length, 3, "ranking value is correct (rank list length) ['a', 'b', 'c'");

ComponentCollection.Instance.clear();
});

0 comments on commit 8e39f30

Please sign in to comment.