This repository has been archived on 2021-06-02. You can view files and clone it, but cannot push or open issues or pull requests.
RealtimeDB-OLD/src/web/helper/form.ts

31 lines
691 B
TypeScript

import { getTemplate } from "./hb";
import { Context } from "vm";
interface IFormConfigField {
type: "text" | "number" | "boolean" | "textarea" | "codemirror";
label: string;
value?: string;
disabled?: boolean;
}
type IFormConfig = { [name: string]: IFormConfigField };
export default function getForm(
url: string,
title: string,
fieldConfig: IFormConfig
): (ctx: Context) => void {
let fields = Object.keys(fieldConfig).map((name) => ({
name,
...fieldConfig[name],
disabled: fieldConfig.disabled ? "disabled" : "",
}));
return (ctx) =>
(ctx.body = getTemplate("forms")({
url,
title,
fields,
}));
}