From e37170d3becd6f43d9f7779d38afd2cd787e6248 Mon Sep 17 00:00:00 2001
From: ks129 <45097959+ks129@users.noreply.github.com>
Date: Mon, 18 Jan 2021 17:53:43 +0200
Subject: Add required validator for ShortText

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

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

diff --git a/src/components/Question.tsx b/src/components/Question.tsx
index 0c32ed5..3994950 100644
--- a/src/components/Question.tsx
+++ b/src/components/Question.tsx
@@ -80,6 +80,12 @@ class RenderedQuestion extends React.Component<QuestionProp> {
             event.target.parentElement.classList.toggle("unselected");
             event.target.parentElement.classList.toggle("selected");
         }
+
+        switch (event.target.type) {
+            case "text":
+                this.setPublicState("valid", true);
+                break;
+        }
     }
 
     text_area_handler(event: ChangeEvent<HTMLTextAreaElement>): void {
@@ -93,7 +99,16 @@ class RenderedQuestion extends React.Component<QuestionProp> {
     // eslint-disable-next-line @typescript-eslint/no-empty-function
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     on_blur_handler(event: FocusEvent<HTMLInputElement>): void {
-        
+        if (this.props.question.required) {
+            switch (event.target.type) {
+                case "text":
+                    if (event.target.value === "") {
+                        this.setPublicState("error", "Field must be filled.");
+                        this.setPublicState("valid", false);
+                    }
+                    break;
+            }
+        }
     }
 
     on_blur_textarea_handler(event: FocusEvent<HTMLTextAreaElement>): void {
-- 
cgit v1.2.3

