From fca981602f54d818300d07c4b346b347b6c34f1d Mon Sep 17 00:00:00 2001
From: Ellen-Wittingen <101463776+Ellen-Wittingen@users.noreply.github.com>
Date: Fri, 20 May 2022 12:50:31 +0200
Subject: [PATCH] fix: proper ordering of closed question answers in form
responses (#553)
---
app/components/form/responses-table-totals.hbs | 2 +-
app/models/form/response.js | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/components/form/responses-table-totals.hbs b/app/components/form/responses-table-totals.hbs
index f0669f56a..d8ab54cba 100644
--- a/app/components/form/responses-table-totals.hbs
+++ b/app/components/form/responses-table-totals.hbs
@@ -9,7 +9,7 @@
{{#if question.isOpenQuestion}}
{{question.sumOfAnswers}}
{{else}}
- {{#each question.options as |opt|}}
+ {{#each question.sortedOptions as |opt|}}
{{opt.sumOfAnswers}}
{{opt.option}}
{{/each}}
diff --git a/app/models/form/response.js b/app/models/form/response.js
index c52e86f79..15a326524 100644
--- a/app/models/form/response.js
+++ b/app/models/form/response.js
@@ -32,6 +32,11 @@ export default class Response extends DirtySaveModel {
await this.closedQuestionAnswers
).map((closedQuestionAnswer) => closedQuestionAnswer.option)
);
+ answers.sort((answer1, answer2) =>
+ answer1.option && answer2.option
+ ? answer1.option.get('position') - answer2.option.get('position')
+ : 0
+ );
return answers;
})
.then(this.groupAnswers);