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 18, 2024
1 parent 8cd6640 commit 4c5f191
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/dragdrop/ranking-select-to-rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ export class DragDropRankingSelectToRank extends DragDropRankingChoices {
const unRankingChoices = questionModel.unRankingChoices;
const item = unRankingChoices[fromIndex];

questionModel.isValueSetByUser = true;
rankingChoices.splice(toIndex, 0, item);
questionModel.setPropertyValue("rankingChoices", rankingChoices);
}

public unselectFromRank(questionModel: QuestionRankingModel, fromIndex: number, toIndex?: number): void {
const rankingChoices = questionModel.rankingChoices;
questionModel.isValueSetByUser = true;
rankingChoices.splice(fromIndex, 1);
questionModel.setPropertyValue("rankingChoices", rankingChoices);
}
Expand All @@ -155,6 +157,7 @@ export class DragDropRankingSelectToRank extends DragDropRankingChoices {
const rankingChoices = questionModel.rankingChoices;
const item = rankingChoices[fromIndex];

questionModel.isValueSetByUser = true;
rankingChoices.splice(fromIndex, 1);
rankingChoices.splice(toIndex, 0, item);
questionModel.setPropertyValue("rankingChoices", rankingChoices);
Expand Down
21 changes: 8 additions & 13 deletions 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 && !this.isValueSetByUser) {
if (this.carryForwardStartUnranked && !this.isValueSetByUser && !this.selectToRankEnabled) {
this.value = [];
}

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

private isValueSetByUser = false;
public isValueSetByUser = false;
public setValue = (): void => {
const value: string[] = [];
this.rankingChoices.forEach((choice: ItemValue) => {
Expand Down Expand Up @@ -498,16 +498,11 @@ export class QuestionRankingModel extends QuestionCheckboxModel {
this.setPropertyValue("selectToRankEnabled", val);
}

/**
* Unraked all items (remove value) if choices dynamically changed (e.g. with carry forward)
*
* Default value: `false`
*/
public get unrankIfChoicesChanged(): boolean {
return this.getPropertyValue("unrankIfChoicesChanged", false);
public get carryForwardStartUnranked(): boolean {
return this.getPropertyValue("carryForwardStartUnranked", true);
}
public set unrankIfChoicesChanged(val: boolean) {
this.setPropertyValue("unrankIfChoicesChanged", val);
public set carryForwardStartUnranked(val: boolean) {
this.setPropertyValue("carryForwardStartUnranked", val);
}

/**
Expand Down Expand Up @@ -623,8 +618,8 @@ Serializer.addClass(
},
},
{
name: "unrankIfChoicesChanged:switch",
default: false,
name: "carryForwardStartUnranked",
default: true,
visible: false,
isSerializable: true,
},
Expand Down
5 changes: 2 additions & 3 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ QUnit.test("Ranking: Carry Forward and unrankIfChoicesChanged", function(assert)

checkboxQuestion.value = [1];
checkboxQuestion.value = [1, 2];
assert.equal(rankingQuestion.value.length, 2, "rank items by default");
assert.equal(rankingQuestion.value.length, 0, "rank items by default");

rankingQuestion.unrankIfChoicesChanged = true;
checkboxQuestion.value = [1, 2, 3];
assert.equal(rankingQuestion.value.length, 0, "unrank items after choices changed");

Expand Down Expand Up @@ -345,7 +344,7 @@ QUnit.test("Ranking: items visibleIf and value, Bug#5959", function(assert) {
var q2 = <QuestionRankingModel>survey.getQuestionByName("q2");
q2.value = ["c", "d", "a", "b"];
q1.value = [1];
assert.deepEqual(q2.value, ["a", "b"], "value is correct");
assert.deepEqual(q2.value, [], "value is correct");
assert.equal(q2.rankingChoices.length, 2, "2 items are shown");
});
QUnit.test("Ranking: strict compare, Bug#6644", function(assert) {
Expand Down

0 comments on commit 4c5f191

Please sign in to comment.