Skip to content

Commit

Permalink
work for the #8541
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov committed Jul 15, 2024
1 parent d7436b1 commit 8e709a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/question_ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class QuestionRankingModel extends QuestionCheckboxModel {
protected onVisibleChoicesChanged = (): void => {
super.onVisibleChoicesChanged();

if (this.carryForwardStartUnranked && !this.isValueSetByUser && !this.selectToRankEnabled) {
if (this.carryForwardStartUnranked && !this.isValueSetByUser && !this.selectToRankEnabled && !this.defaultValue) {
this.value = [];
}

Expand Down
34 changes: 34 additions & 0 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,40 @@ QUnit.test("Ranking: Carry Forward and unrankIfChoicesChanged", function(assert)
assert.equal(rankingQuestion.value.length, 2, "after user's arrengement unrank should stop working");
});

QUnit.test("Ranking: Carry Forward: Default Value", function(assert) {
var survey = new SurveyModel({
elements: [
{
"type": "checkbox",
"name": "q1",
"defaultValue": [1, 2, 3],
"choices": [1, 2, 3, 4]
},
{
"type": "ranking",
"name": "q2",
"defaultValue": [1, 2, 3],
"choicesFromQuestion": "q1",
"choicesFromQuestionMode": "selected"
}
]
});
var q1 = <QuestionCheckboxModel>survey.getQuestionByName("q1");
var q2 = <QuestionRankingModel>survey.getQuestionByName("q2");

assert.deepEqual(survey.data, {
q1: [1, 2, 3],
q2: [1, 2, 3],
});

q1.value = [1, 2];

assert.deepEqual(survey.data, {
q1: [1, 2],
q2: [1, 2],
});
});

QUnit.test("Ranking: CorrectAnswer, Bug#3720", function(assert) {
var survey = new SurveyModel({
elements: [
Expand Down

0 comments on commit 8e709a1

Please sign in to comment.