Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188624
form.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
form.ts
View Options
import
{
curryImportPath
}
from
"../utils/import-path.js"
;
export
async
function
formTemplate
(
action_name
:
string
,
newfilefullpath
:
string
)
:
Promise
<
string
>
{
const
rel
=
curryImportPath
(
newfilefullpath
);
return
`import type { Context } from "koa";
import type { FormData, FormDataValue } from "@sealcode/sealgen";
import { Form, Fields, Controls, fieldsToShape } from "@sealcode/sealgen";
import html from "
${
rel
(
"src/back/html.js"
)
}
";
import { Users } from "
${
rel
(
"src/back/collections/collections.js"
)
}
";
export const actionName = "
${
action_name
}
";
const fields = {
email: new Fields.CollectionField(true, Users.fields.email),
password: new Fields.SimpleFormField(true),
};
export const
${
action_name
}
Shape = fieldsToShape(fields);
export default new (class
${
action_name
}
Form extends Form<typeof fields, void> {
defaultSuccessMessage = "Formularz wypełniony poprawnie";
fields = fields;
controls = [
new Controls.SimpleInput(fields.email, { label: "Email:", type: "email" }),
new Controls.SimpleInput(fields.password, {
label: "Password:",
type: "password",
}),
];
async validateValues(
ctx: Context,
data: Record<string, FormDataValue>
): Promise<{ valid: boolean; error: string }> {
// just a silly example, please remove this with better logic
const { parsed: email } = await this.fields.email.getValue(ctx, data);
const { parsed: password } = await this.fields.password.getValue(ctx, data);
if ((password || "").length > ((email as string) || "").length) {
return { valid: false, error: "Password cannot be longer than email" };
} else {
return { valid: true, error: "" };
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async canAccess(_: Context) {
return { canAccess: true, message: "" };
}
async onSubmit() {
//noop
return;
}
async render(ctx: Context, data: FormData, show_field_errors: boolean) {
return html(ctx, "
${
action_name
}
", await super.render(ctx, data, show_field_errors));
}
})();
`
;
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 08:22 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
626281
Default Alt Text
form.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment