From 66d375b041a5d70a99b83d2101f0417f07457c31 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Thu, 18 Feb 2021 08:10:07 +0200 Subject: Revert change of gathering checkbox values --- src/pages/FormPage.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/pages/FormPage.tsx') diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx index d5f37f4..516d937 100644 --- a/src/pages/FormPage.tsx +++ b/src/pages/FormPage.tsx @@ -247,6 +247,7 @@ function FormPage(): JSX.Element { const answers: { [key: string]: unknown } = {}; questions.forEach(prop => { const question: Question = prop.props.question; + const options: string | string[] = question.data["options"]; // TODO: Parse input from each question, and submit switch (question.type) { @@ -255,15 +256,17 @@ function FormPage(): JSX.Element { break; case QuestionType.Checkbox: { - const parsed: { [key: string]: unknown } = {}; - - prop.props.public_state.forEach((value: unknown, key: string) => { - if (key !== "valid" && key !== "error") { - parsed[key.slice(6)] = value; - } - }); - - answers[question.id] = parsed; + if (typeof options !== "string") { + const keys: Map = new Map(); + options.forEach((val: string, index) => { + keys.set(val, `${("000" + index).slice(-4)}. ${val}`); + }); + const pairs: { [key: string]: boolean } = { }; + keys.forEach((val, key) => { + pairs[key] = !!prop.props.public_state.get(val); + }); + answers[question.id] = pairs; + } break; } -- cgit v1.2.3