Closed JaneSjs closed 2 weeks ago
I got a reply from @OlgaLarina. The survey.onChoicesLazyLoad
event's options.setItems
callback function should either accept an array of strings or of the { value: XXX, text: YYY }
objects. Therefore, it is necessary to update the code as follows: View Demo.
survey.onChoicesLazyLoad.add((_, options) => {
if (options.question.name === "dropdown1") {
const dropdownItems = dropdown1Values.map((item) => {
return {
value: item.id,
text: item.title,
values: item.values,
};
});
options.setItems(dropdownItems, dropdownItems.length);
}
if (options.question.name === "dropdown2") {
const dropdown1 = options.question.parent.getQuestionByName("dropdown1");
const selectedItem = dropdown1.selectedItem;
if (!!selectedItem) {
const dropdown2Choices = dropdown1.selectedItem.values.map((item) => {
return { value: item.value, text: item.text };
});
options.setItems(dropdown2Choices, dropdown2Choices.length);
}
}
});
T20594 - Specify as many forms as i need whit its corresponding form question name https://surveyjs.answerdesk.io/internal/ticket/details/T20594
Please consider the following demo: View CodeSandbox. To reproduce the issue, select dropdown 1, dropdown 2. Re-open dropdown 2: a list appears empty even though the
options.setItems(selectedItem.values, selectedItem.values.length)
function seems to be invoked with a correct item value array.