Merged in feature/matrix-solutions (pull request #59)

Parse answers from survey matrix
This commit is contained in:
Ramon Wenger 2020-04-14 11:22:04 +00:00
commit 700b899a23
2 changed files with 13 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,22 @@
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 prop of Object.keys(answerObject)) {
keysAndValues.push(`${prop}: ${answerObject[prop]}`);
}
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>
`
}, '')
}