Page MenuHomeSealhub

multiform.ts
No OneTemporary

multiform.ts

import { curryImportPath } from "../utils/utils";
export async function multiformTemplate(
action_name: string,
newfilefullpath: string
): Promise<string> {
const rel = curryImportPath(newfilefullpath);
return `import { Context } from "koa";
import html from "${rel("src/back/html.js")}";
import { Controls, Fields, Form, FormMessage, Multiform } from "@sealcode/sealgen";
import { FlatTemplatable } from "tempstream";
export const actionName = "${action_name}";
const fields1 = {
email: new Fields.SimpleFormField(true),
password: new Fields.SimpleFormField(true),
};
const form1 = new (class extends Form<typeof fields1> {
defaultSuccessMessage = "Form1 done!";
controls = [
new Controls.FormHeader("form1"),
new Controls.SimpleInput(fields1.email),
];
fields = fields1;
onSubmit() {
console.log("form1 submit");
}
})();
const fields2 = {
name: new Fields.SimpleFormField(true),
surname: new Fields.SimpleFormField(true),
};
const form2 = new (class extends Form<Record<never, unknown>> {
defaultSuccessMessage = "Form2 done!";
controls = [new Controls.FormHeader("form2"), new Controls.SimpleInput(fields2.name)];
fields = fields2;
onSubmit() {
console.log("form2 submit");
}
})();
export default new (class extends Multiform {
name = "multiform_test";
forms = { form1, form2 };
async render(
ctx: Context,
messages: FormMessage[],
prerenderedForms?: Record<string, FlatTemplatable | undefined>
): Promise<FlatTemplatable> {
return html(ctx, "${action_name}", await super.render(ctx, messages, prerenderedForms));
}
})();
`;
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Jan 24, 15:15 (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601606
Default Alt Text
multiform.ts (1 KB)

Event Timeline