From ff1e4bc4d37fb55aeb5b33cbb8b4f640e9fc745e Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 8 Feb 2021 16:31:29 +0200 Subject: Improve and simplify checkboxes gathering Co-authored-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- src/pages/FormPage.tsx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/pages') diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx index de80e8a..b8518c0 100644 --- a/src/pages/FormPage.tsx +++ b/src/pages/FormPage.tsx @@ -244,19 +244,18 @@ function FormPage(): JSX.Element { answers[question.id] = ""; break; - case QuestionType.Checkbox: - if (typeof options !== "string") { - const keys: Map = new Map(); - options.forEach((val, index) => { - keys.set(val, `${("000" + index).slice(-4)}. ${val}`); - }); - const pairs = {}; - keys.forEach((val, key) => { - pairs[key] = !!prop.props.public_state.get(val); - }); - answers[question.id] = pairs; - } + case QuestionType.Checkbox: { + const parsed = new Map(); + + prop.props.public_state.forEach((value, key) => { + if (key !== "valid" && key !== "error") { + answers.set(key.slice(6), value); + } + }); + + answers[question.id] = parsed; break; + } default: answers[question.id] = prop.props.public_state.get("value"); -- cgit v1.2.3