Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010062
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"
;
export
async
function
formTemplate
(
action_name
:
string
,
newfilefullpath
:
string
)
:
Promise
<
string
>
{
const
rel
=
curryImportPath
(
newfilefullpath
);
return
`import { Context } from "koa";
import { Form, FormData, FormDataValue, Fields, Controls } from "@sealcode/sealgen";
import html from "
${
rel
(
"src/back/html"
)
}
";
import { Users } from "
${
rel
(
"src/back/collections/collections"
)
}
";
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 = Fields.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 an example
const { parsed: email } = await this.fields.email.getValue(ctx, data);
const { parsed: password } = await this.fields.password.getValue(ctx, data);
if ((password || "").length > (email || "").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
Wed, May 7, 19:36 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
633847
Default Alt Text
form.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment