Page MenuHomeSealhub

autocomplete.ts
No OneTemporary

autocomplete.ts

import { Context } from "koa";
import { PickFromListField } from "../fields/pick-from-list";
import { FormDataValue } from "../form";
import { SimpleInput } from "./simple-input";
export class Autocomplete extends SimpleInput<string | null> {
constructor(
public field: PickFromListField<boolean>,
public options: { id?: string; label?: string; placeholder?: string }
) {
super(field);
}
getListID(): string {
return this.getID() + "_list";
}
async getInputAttributes(
ctx: Context,
data: Record<string, FormDataValue>,
field_prefix: string,
form_id: string
) {
return {
...(await super.getInputAttributes(
ctx,
data,
field_prefix,
form_id
)),
list: this.getListID(),
};
}
async postInput(ctx: Context) {
return /* HTML */ `<datalist id="${this.getListID()}">
${Object.entries(await this.field.generateOptions(ctx)).map(
([key, value]) => /* HTML */ `<option>${key}</option>`
)}
</datalist>`;
}
}

File Metadata

Mime Type
text/x-java
Expires
Tue, Jul 8, 08:15 (23 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
798102
Default Alt Text
autocomplete.ts (970 B)

Event Timeline