Skip to content

Commit

Permalink
Work for surveyjs/survey-pdf#280: fix isReady always false when call …
Browse files Browse the repository at this point in the history
…options.setItems([])
  • Loading branch information
dk981234 committed Sep 29, 2023
1 parent 29cf60c commit 43aeea1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ export class QuestionSelectBase extends Question {
values: valueArray,
setItems: (displayValues: Array<string>, ...customValues: Array<IValueItemCustomPropValues>) => {
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)) {
Expand Down
18 changes: 18 additions & 0 deletions tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionDropdownModel>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();

Expand Down

0 comments on commit 43aeea1

Please sign in to comment.