aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-01-18 11:36:39 +0200
committerGravatar ks129 <[email protected]>2021-01-18 11:36:39 +0200
commit5b9d94583f33795548d37fc890189167713c9a3f (patch)
tree374064a7a8d275b0b0eec57e3ce980f3297193b4 /src
parentDisplay invalid information for TextArea (diff)
Provide valid and error message data to TextArea component
Diffstat (limited to 'src')
-rw-r--r--src/components/InputTypes/index.tsx13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/components/InputTypes/index.tsx b/src/components/InputTypes/index.tsx
index a597c94..2481d64 100644
--- a/src/components/InputTypes/index.tsx
+++ b/src/components/InputTypes/index.tsx
@@ -24,6 +24,15 @@ export default function create_input({ question, public_state }: QuestionProp, h
// eslint-disable-next-line
// @ts-ignore
let options: string[] = question.data["options"];
+ let valid = true;
+ if (!public_state.get("valid")) {
+ valid = false;
+ }
+ const rawError = public_state.get("error");
+ let error = "";
+ if (typeof rawError === "string") {
+ error = rawError;
+ }
// Catch input types that require options but don't have any
if ((options === undefined || typeof options !== "object") && require_options.includes(question.type)) {
@@ -34,7 +43,7 @@ export default function create_input({ question, public_state }: QuestionProp, h
/* eslint-disable react/react-in-jsx-scope */
switch (question.type) {
case QuestionType.TextArea:
- result = <TextArea handler={handler} required={question.required} />;
+ result = <TextArea handler={handler} required={question.required} valid={valid} error={error} />;
break;
case QuestionType.Checkbox:
@@ -63,7 +72,7 @@ export default function create_input({ question, public_state }: QuestionProp, h
break;
default:
- result = <TextArea handler={handler} required={question.required}/>;
+ result = <TextArea handler={handler} required={question.required} valid={valid} error={error}/>;
}
/* eslint-enable react/react-in-jsx-scope */