Page MenuHomeSealhub

autocomplete.ts
No OneTemporary

autocomplete.ts

import { Context } from "koa";
import { FlatTemplatable } from "tempstream";
import { attribute } from "../../sanitize";
import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper";
import { PickFromListField } from "../fields/pick-from-list";
import { FormDataValue } from "../form";
import { FormFieldControl } from "./form-field-control";
import { SimpleInput } from "./simple-input";
export class Autocomplete extends SimpleInput<string> {
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
Wed, May 7, 19:42 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
674890
Default Alt Text
autocomplete.ts (1 KB)

Event Timeline