diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index 48e81db35c..b1ebfb0ad5 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -137,6 +137,7 @@ export class QuestionSelectBase extends Question { super.localeChanged(); if (this.choicesOrder !== "none") { this.updateVisibleChoices(); + this.onVisibleChoicesChanged(); } } public locStrsChanged(): void { diff --git a/tests/dropdown_list_model_test.ts b/tests/dropdown_list_model_test.ts index 8ffd05193a..f76d29b2de 100644 --- a/tests/dropdown_list_model_test.ts +++ b/tests/dropdown_list_model_test.ts @@ -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); -}); \ No newline at end of file +}); +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 = 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"); +}); diff --git a/tests/question_baseselecttests.ts b/tests/question_baseselecttests.ts index 006e0547e9..6e974789ad 100644 --- a/tests/question_baseselecttests.ts +++ b/tests/question_baseselecttests.ts @@ -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 = 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"); +});