aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-01-19 08:12:16 +0200
committerGravatar ks129 <[email protected]>2021-01-19 08:12:16 +0200
commitcf8e125c867ff01852a03a6eb107be2e2cc96c8f (patch)
treed409d227b58fb22ff24edb5d7871306353b091e6 /src
parentImplement shadow for Select (diff)
Implement validation for checkboxes
Diffstat (limited to 'src')
-rw-r--r--src/components/Question.tsx18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/components/Question.tsx b/src/components/Question.tsx
index 12cde5d..81c43b2 100644
--- a/src/components/Question.tsx
+++ b/src/components/Question.tsx
@@ -113,10 +113,28 @@ class RenderedQuestion extends React.Component<QuestionProp> {
event.target.parentElement.classList.toggle("selected");
}
+ const options: string | string[] = this.props.question.data["options"];
switch (event.target.type) {
case "text":
this.setPublicState("valid", true);
break;
+
+ case "checkbox":
+ // We need to check this here, because checkbox doesn't have onBlur
+ if (this.props.question.required && typeof options !== "string") {
+ const keys: string[] = [];
+ options.forEach((val, index) => {
+ keys.push(`${("000" + index).slice(-4)}. ${val}`);
+ });
+ if (keys.every(v => !this.props.public_state.get(v))) {
+ this.setPublicState("error", "Field must be filled.");
+ this.setPublicState("valid", false);
+ } else {
+ this.setPublicState("error", "");
+ this.setPublicState("valid", true);
+ }
+ }
+ break;
}
}