happyDomain/ui/src/lib/types.ts

14 lines
683 B
TypeScript
Raw Normal View History

2023-01-08 17:44:01 +00:00
import type { Field } from '$lib/model/custom_form';
export function fillUndefinedValues(value: any, spec: Field) {
2023-01-11 10:01:08 +00:00
if (value[spec.id] === undefined && spec.type.length) {
let vartype = spec.type;
if (vartype[0] == "*") vartype = vartype.substring(1);
2023-01-18 16:30:06 +00:00
if (spec.default !== undefined) value[spec.id] = spec.default;
else if (vartype == "[]uint8") value[spec.id] = "";
2023-01-11 10:01:08 +00:00
else if (vartype.startsWith("[]")) value[spec.id] = [];
else if (vartype != "string" && !vartype.startsWith("uint") && !vartype.startsWith("int") && vartype != "net.IP" && vartype != "time.Duration" && vartype != "common.Duration") value[spec.id] = { };
2023-01-08 17:44:01 +00:00
}
}