diff --git a/src/question_ranking.ts b/src/question_ranking.ts index d2a9bc961a..90647cf1c2 100644 --- a/src/question_ranking.ts +++ b/src/question_ranking.ts @@ -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 = []; } diff --git a/tests/question_ranking_tests.ts b/tests/question_ranking_tests.ts index b864270db9..97bff77771 100644 --- a/tests/question_ranking_tests.ts +++ b/tests/question_ranking_tests.ts @@ -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 = survey.getQuestionByName("q1"); + var q2 = 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: [