Parse answers from survey matrix

This commit is contained in:
Ramon Wenger 2020-04-14 10:43:27 +02:00
parent 5da7665f79
commit 10078cde5f
2 changed files with 15 additions and 2 deletions

View File

@ -43,5 +43,4 @@
@import "@/styles/_variables.scss";
@import "@/styles/_mixins.scss";
@import "@/styles/_default-layout.scss";
</style>

View File

@ -59,10 +59,24 @@
if (!answer.answer) {
return previous
}
let answerText;
if (typeof answer.answer === 'object') {
// this means the answer comes from a matrix, where the keys are the labels and the values are the respective answers
let answerObject = answer.answer;
let keysAndValues = [];
for (let i in answerObject) {
if (answerObject.hasOwnProperty(i)) {
keysAndValues.push(`${i}: ${answerObject[i]}`);
}
}
answerText = keysAndValues.join(', ');
} else {
answerText = answer.answer;
}
return `
${previous}
<h2 class="solution-text__heading">${answer.title}</h2>
<p class="solution-text__answer">${answer.answer}</p>
<p class="solution-text__answer">${answerText}</p>
`
}, '')
}