summaryrefslogtreecommitdiff
path: root/site/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'site/index.html')
-rw-r--r--site/index.html38
1 files changed, 30 insertions, 8 deletions
diff --git a/site/index.html b/site/index.html
index 4034787..70d487b 100644
--- a/site/index.html
+++ b/site/index.html
@@ -43,6 +43,12 @@
return p;
}
+ function setErrormsg (element, msg=null) {
+ element.hidden = msg === null;
+ if (!element.hidden)
+ element.innerText = msg;
+ return element;
+ }
/// creates an option with a label next to it.
/// mainly for list-like things, but also the password field
@@ -59,17 +65,25 @@
// for all kinds of multiple-choise like answer spaces
function mkListSpace(kind, options, qid, label) {
- let ul = mkElement("fieldset");
let buttons = options.map((option) =>
mkOption(kind, option, qid)
);
- appendChildren (ul, [
+ let fieldset = appendChildren (
+ mkElement("fieldset"), [
mkElement("legend", label)
].concat(buttons.map((button) => {
let li = mkElement("li");
appendChildren(li, button);
return li;
})));
+ let errormsg = setErrormsg(
+ mkElement("p", "", "error"),
+ null
+ );
+ let div = appendChildren(
+ mkElement("div"),
+ [fieldset, errormsg]
+ )
// return the answer chosen by the user. This function uses
// null to indicate that a choice was invalid, i.e. the form
// is not ready for submission yet.
@@ -77,13 +91,21 @@
let selected = buttons
.filter((b) => b[0].checked)
.map((b) => b[0].value);
- if (kind === "radio")
- return selected.length == 0 ? null : selected[0];
- if (kind === "checkbox")
- return selected;
- console.err("PartialityError: encountered unknown list type!")
+
+ // a weird attempt at pattern matching in js, misusing
+ // an array where one field must always be null as something
+ // that would otherwise be a sum type
+ let [ret, error] =
+ kind === "radio"
+ ? (selected.length != 0
+ ? [selected[0], null]
+ : [null, _("Have to select an option")])
+ : kind === "checkbox" ? [selected, null]
+ : [null, "PartialityError: encountered unknown type of list space"];
+ setErrormsg (errormsg, error);
+ return ret;
}
- return [ul, getAnswer];
+ return [div, getAnswer];
}
// for freeform text answers (TODO)