diff options
author | 2021-02-08 16:31:29 +0200 | |
---|---|---|
committer | 2021-02-08 16:31:29 +0200 | |
commit | ff1e4bc4d37fb55aeb5b33cbb8b4f640e9fc745e (patch) | |
tree | 0798393c38150c7db06daf80f724c69cf3351b9f /src/pages | |
parent | Use public state instead of event value for compability (diff) |
Improve and simplify checkboxes gathering
Co-authored-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/FormPage.tsx | 23 |
1 files changed, 11 insertions, 12 deletions
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<string, string> = 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"); |