diff --git a/src/question_checkbox.ts b/src/question_checkbox.ts index ea3eaabfab..7c5a86c75e 100644 --- a/src/question_checkbox.ts +++ b/src/question_checkbox.ts @@ -206,12 +206,15 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase { * @see enabledChoices */ public get selectedChoices(): Array { + const val = this.renderedValue as Array; + const visChoices = this.visibleChoices; + const selectedItemValues = this.selectedItemValues; + if (this.isEmpty()) return []; - const val = this.renderedValue as Array; - const allChoices = !!this.defaultSelectedItemValues ? [].concat(this.defaultSelectedItemValues, this.visibleChoices) : this.visibleChoices; + const allChoices = !!this.defaultSelectedItemValues ? [].concat(this.defaultSelectedItemValues, visChoices) : visChoices; const itemValues = val.map((item) => { return ItemValue.getItemByValue(allChoices, item); }).filter(item => !!item); - if(!itemValues.length && !this.selectedItemValues) { + if(!itemValues.length && !selectedItemValues) { this.updateSelectedItemValues(); } diff --git a/src/vue/components/tagbox/tagbox.vue b/src/vue/components/tagbox/tagbox.vue index e40647ca06..74448864a9 100644 --- a/src/vue/components/tagbox/tagbox.vue +++ b/src/vue/components/tagbox/tagbox.vue @@ -21,7 +21,7 @@ >
{ .expect(selectedItems.count).eql(0); }); + test("Check default value", async (t) => { + await initSurvey(framework, { + "elements": [ + { + "type": "tagbox", + "isRequired": true, + "choicesByUrl": { + "url": "http://127.0.0.1:8080/testCafe/countriesMock.json", + path: "RestResponse;result", + valueName: "name" + }, + "name": "countries", + "defaultValue": ["Cuba", "Romania"], + } + ], + }); + await t + .expect(selectedItems.count).eql(2) + .expect(selectedItems.nth(0).textContent).contains("Cuba") + .expect(selectedItems.nth(1).textContent).contains("Romania") + + .click(questionTagbox) + .click(getListItemByText("United States")) + .pressKey("esc") + .expect(selectedItems.count).eql(3) + .expect(selectedItems.nth(0).textContent).contains("Cuba") + .expect(selectedItems.nth(1).textContent).contains("Romania") + .expect(selectedItems.nth(2).textContent).contains("United States"); + }); + const theme = "defaultV2"; function choicesLazyLoad(_, opt) {