Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown - choicesOrder doesn't work correctly for a custom locale fi… #6956

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class QuestionSelectBase extends Question {
super.localeChanged();
if (this.choicesOrder !== "none") {
this.updateVisibleChoices();
this.onVisibleChoicesChanged();
}
}
public locStrsChanged(): void {
Expand Down
19 changes: 18 additions & 1 deletion tests/dropdown_list_model_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,4 +863,21 @@ QUnit.test("Dropdown should noy be open on click in design mode", (assert) => {

dropdownListModel.onClick(new Event("click"));
assert.notOk(dropdownListModel.popupModel.isVisible);
});
});
QUnit.test("order & locale change", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "dropdown", name: "q1", choicesOrder: "asc",
choices: [{ value: "A", text: { default: "AA", de: "BAA" } },
{ value: "B", text: { default: "BB", de: "ABB" } }] }
] });
const question = <QuestionDropdownModel>survey.getQuestionByName("q1");
let list: ListModel = question.popupModel.contentComponentData.model as ListModel;
assert.equal(list.actions.length, 2, "Two items");
assert.equal(list.actions[0].id, "A", "action[0].id");
assert.equal(list.actions[1].id, "B", "action[1].id");
survey.locale = "de";
list = question.popupModel.contentComponentData.model as ListModel;
assert.equal(list.actions.length, 2, "Two items");
assert.equal(list.actions[0].id, "B", "action[0].id, de");
assert.equal(list.actions[1].id, "A", "action[1].id, de");
});
21 changes: 21 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,3 +1276,24 @@ QUnit.test("Use carryForward with panel dynamic + choiceValuesFromQuestion + val
assert.equal(q2_q2.visibleChoices[0].value, "aaa", "the first value is correct");
assert.equal(q2_q2.visibleChoices[1].value, "bbb", "the second value is correct");
});
QUnit.test("SelectBase visibleChoices order & locale change", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "dropdown", name: "q1", choicesOrder: "asc",
choices: [{ value: "A", text: { default: "AA", de: "BAA" } },
{ value: "B", text: { default: "BB", de: "ABB" } }] }
] });
const question = <QuestionSelectBase>survey.getQuestionByName("q1");
assert.equal(question.visibleChoices.length, 2, "There are 4 items");
assert.equal(question.visibleChoices[0].value, "A", "the first item");
assert.equal(question.visibleChoices[1].value, "B", "the second item");
survey.locale = "de";
assert.equal(question.choicesOrder, "asc", "The order is correct");
assert.equal(question.getLocale(), "de", "question locale is correct");
assert.equal(question.choices[0].calculatedText, "BAA", "the first item calculatedText, de");
assert.equal(question.choices[1].calculatedText, "ABB", "the second item calculatedText, de");
assert.equal(question.choices[0].getLocale(), "de", "ItemValue locText locale is correct");
assert.equal(question.visibleChoices[0].value, "B", "the first item, de");
assert.equal(question.visibleChoices[1].value, "A", "the second item, de");
assert.equal(question.visibleChoices[0].calculatedText, "ABB", "the first visible item calculatedText, de");
assert.equal(question.visibleChoices[1].calculatedText, "BAA", "the second visible item calculatedText, de");
});