Skip to content

Commit

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

if (this.unrankIfChoicesChanged) {
if (this.unrankIfChoicesChanged && !this.isValueSetByUser) {
this.value = [];
}

Expand Down Expand Up @@ -446,12 +446,14 @@ export class QuestionRankingModel extends QuestionCheckboxModel {
}
};

private isValueSetByUser = false;
public setValue = (): void => {
const value: string[] = [];
this.rankingChoices.forEach((choice: ItemValue) => {
value.push(choice.value);
});
this.value = value;
this.isValueSetByUser = true;
};
public getIconHoverCss(): string {
return new CssClassBuilder()
Expand Down
6 changes: 6 additions & 0 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ QUnit.test("Ranking: Carry Forward and unrankIfChoicesChanged", function(assert)
rankingQuestion.unrankIfChoicesChanged = true;
checkboxQuestion.value = [1, 2, 3];
assert.equal(rankingQuestion.value.length, 0, "unrank items after choices changed");

rankingQuestion["isValueSetByUser"] = true;
rankingQuestion.value = [1, 2, 3];
checkboxQuestion.value = [1, 2];
assert.equal(rankingQuestion.value.length, 2, "after user's arrengement unrank should stop working");
});

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

0 comments on commit 5808579

Please sign in to comment.