From 9a8701a95b476d6c0ccfe814bc0c217e6b860903 Mon Sep 17 00:00:00 2001
From: ks129 <45097959+ks129@users.noreply.github.com>
Date: Mon, 18 Jan 2021 11:32:54 +0200
Subject: Add valid and error to public state and required check for textarea

---
 src/components/Question.tsx | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'src/components/Question.tsx')

diff --git a/src/components/Question.tsx b/src/components/Question.tsx
index 735d69b..7a8c85b 100644
--- a/src/components/Question.tsx
+++ b/src/components/Question.tsx
@@ -27,6 +27,8 @@ class RenderedQuestion extends React.Component<QuestionProp> {
         } else {
             this.handler = this.normal_handler.bind(this);
         }
+        this.setPublicState("valid", true);
+        this.setPublicState("error", "");
 
         if (!skip_normal_state.includes(props.question.type)) {
             this.setPublicState("value", "");
@@ -76,6 +78,13 @@ class RenderedQuestion extends React.Component<QuestionProp> {
     }
 
     text_area_handler(event: ChangeEvent<HTMLTextAreaElement>): void {
+        if (this.props.question.required && event.target.value === "") {
+            this.setPublicState("error", "Field must be filled.");
+            this.setPublicState("valid", false);
+        } else {
+            this.setPublicState("valid", true);
+        }
+
         this.setPublicState("value", event.target.value);
     }
 
-- 
cgit v1.2.3

