Skip to content

Commit

Permalink
tagbox choices by url with default values (#7381)
Browse files Browse the repository at this point in the history
* work for #7362 TagBox - Default values are not displayed and Tag Box becomes unresponsive

* work for #7362 [jQuery] TagBox - Default values are not displayed and Tag Box becomes unresponsive

* work for #7362 fix vue

---------

Co-authored-by: OlgaLarina <[email protected]>
  • Loading branch information
OlgaLarina and OlgaLarina authored Nov 20, 2023
1 parent c2280db commit bb5b8a1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/question_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,15 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase {
* @see enabledChoices
*/
public get selectedChoices(): Array<ItemValue> {
const val = this.renderedValue as Array<any>;
const visChoices = this.visibleChoices;
const selectedItemValues = this.selectedItemValues;

if (this.isEmpty()) return [];

const val = this.renderedValue as Array<any>;
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();
}

Expand Down
5 changes: 4 additions & 1 deletion src/vue/components/tagbox/tagbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
>
<div :class="question.cssClasses.controlValue">
<sv-tagbox-item
v-for="(item, index) in question.selectedChoices"
v-for="(item, index) in selectedChoices"
:item="item"
:question="question"
:key="'item' + index"
Expand Down Expand Up @@ -76,6 +76,9 @@ export class TagboxComponent extends BaseVue {
get model() {
return this.question.dropdownListModel;
}
get selectedChoices() {
return this.question.selectedChoices;
}
getModel() {
return this.model;
}
Expand Down
30 changes: 30 additions & 0 deletions testCafe/questions/tagbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,36 @@ frameworks.forEach((framework) => {
.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) {
Expand Down

0 comments on commit bb5b8a1

Please sign in to comment.