From 43aeea15ba421f53c82396c92b93081511fa1fb3 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Fri, 29 Sep 2023 20:13:27 +0400 Subject: [PATCH] Work for https://github.com/surveyjs/survey-pdf/issues/280: fix isReady always false when call options.setItems([]) --- src/question_baseselect.ts | 5 ++++- tests/questionDropdownTests.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index 0ca9106c1f..c4248bb6d8 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -586,7 +586,10 @@ export class QuestionSelectBase extends Question { values: valueArray, setItems: (displayValues: Array, ...customValues: Array) => { this.waitingGetChoiceDisplayValueResponse = false; - if (!displayValues || !displayValues.length) return; + if (!displayValues || !displayValues.length) { + this.updateIsReady(); + return; + } const items = displayValues.map((displayValue, index) => this.createItemValue(valueArray[index], displayValue)); this.setCustomValuesIntoItems(items, customValues); if(Array.isArray(value)) { diff --git a/tests/questionDropdownTests.ts b/tests/questionDropdownTests.ts index ff79577d93..700ae34dc5 100644 --- a/tests/questionDropdownTests.ts +++ b/tests/questionDropdownTests.ts @@ -1647,6 +1647,24 @@ QUnit.test("isReady flag + onGetChoiceDisplayValue", assert => { assert.ok(question["waitingGetChoiceDisplayValueResponse"]); }); +QUnit.test("isReady flag + onGetChoiceDisplayValue + setItems with empty array", assert => { + const json = { + questions: [{ + "type": "dropdown", + "name": "q1", + "choicesLazyLoadEnabled": true, + }] + }; + const survey = new SurveyModel(json); + const question = survey.getAllQuestions()[0]; + survey.onGetChoiceDisplayValue.add((_, opt) => { + opt.setItems([]); + }); + survey.data = { "q1": "ford" }; + assert.ok(question.isReady); + assert.equal(question.displayValue, "ford"); +}); + QUnit.test("isReady flag + onGetChoiceDisplayValue + choicesRestfull", assert => { const done = assert.async();