mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-23 01:20:11 +00:00
Harvey Tindall
b6ceee508c
invite codes starting with a digit don't work with the webui, so GenerateInvite regenerates uuids until theres one that doesn't.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
function serializeForm(id: string): Object {
|
|
const form = document.getElementById(id) as HTMLFormElement;
|
|
let formData = {};
|
|
for (let i = 0; i < form.elements.length; i++) {
|
|
const el = form.elements[i];
|
|
if ((el as HTMLInputElement).type == "submit") {
|
|
continue;
|
|
}
|
|
let name = (el as HTMLInputElement).name;
|
|
if (!name) {
|
|
name = el.id;
|
|
}
|
|
switch ((el as HTMLInputElement).type) {
|
|
case "checkbox":
|
|
formData[name] = (el as HTMLInputElement).checked;
|
|
break;
|
|
case "text":
|
|
case "password":
|
|
case "email":
|
|
case "number":
|
|
formData[name] = (el as HTMLInputElement).value;
|
|
break;
|
|
case "select-one":
|
|
case "select":
|
|
let val: string = (el as HTMLSelectElement).value.toString();
|
|
if (!isNaN(val as any)) {
|
|
formData[name] = +val;
|
|
} else {
|
|
formData[name] = val;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return formData;
|
|
}
|