aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Question.tsx
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-01-18 11:32:54 +0200
committerGravatar ks129 <[email protected]>2021-01-18 11:32:54 +0200
commit9a8701a95b476d6c0ccfe814bc0c217e6b860903 (patch)
tree0964c40623481b75a2e2e5a0c1d968806f3775ab /src/components/Question.tsx
parentCreate new ErrorMessage component for showing field error messages (diff)
Add valid and error to public state and required check for textarea
Diffstat (limited to 'src/components/Question.tsx')
-rw-r--r--src/components/Question.tsx9
1 files changed, 9 insertions, 0 deletions
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);
}