Open JaneSjs opened 4 months ago
I updated the demo with the purposed API: View Plunker.
function getValue(question){
if(question.isDescendantOf("checkbox")) {
const res = [];
question.selectedItems.forEach(item => res.push({ id: item.value, text: item.text }));
return res;
} else {
if(question.isDescendantOf("selectbase")) {
const item = question.selectedItem;
return { id: item.value, text: item.text };
}
}
return value;
};
survey.onComplete.add((survey) => {
const resultData = [];
for (const key in survey.data) {
const question = survey.getQuestionByName(key);
if (!!question) {
if(!!question.choices){
const item = {
name: question.name,
value: []
};
item.value = getValue(question);
resultData.push(item);
} else {
const item = {
name: key,
value: question.value
};
resultData.push(item);
}
}
}
// Send data to a storage
console.log(JSON.stringify(resultData, null, 3));
});
Updated:
Suggested API:
The function will call the callback function that is passed as a parameter for all questions including matrix cell questions, inside dyanamic panels and composite components.
T16847 - Store full object for Dropdown, Multi Checkboxes questions https://surveyjs.answerdesk.io/internal/ticket/details/T16847
Currently,
survey.data
contains selected choice values in the following format:Introduce an option to store the entire choice object (
{ value: XXX, text: YYY}
or{ id: XXX, text: YYY }
) within survey results. An example of a required output format:In the meantime, it can be achieved by generating a custom response object within the
survey.onComplete
function: View Plunker.