Page MenuHomeSealhub

mountable-with-fields.test.ts
No OneTemporary

mountable-with-fields.test.ts

import type { Context } from "koa";
import { Form } from "../forms/form.js";
import { FieldTypes } from "sealious";
import { CollectionField } from "../forms/fields/collection-field.js";
import { FormData } from "../forms/form-types.js";
describe("mountable-with-fields", () => {
it("properly types the getParsedValues method and respects required status", () => {
const fields = {
not_required: new CollectionField(false, new FieldTypes.Text()),
required: new CollectionField(true, new FieldTypes.Text()),
};
new (class extends Form<typeof fields, void> {
fields = fields;
controls = [];
async onSubmit(ctx: Context, form_values: FormData) {
const data = await this.getParsedValues(ctx);
// this should not throw a Typescript error
data.not_required?.trim();
// this should work without the optional chaining:
data.required.trim();
const { parsed: data2 } = await this.fields.not_required.getValue(
ctx,
form_values.raw_values
);
data2?.trim();
}
})();
});
});

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:49 (20 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625546
Default Alt Text
mountable-with-fields.test.ts (1 KB)

Event Timeline