Page MenuHomeSealhub

autocomplete.ts
No OneTemporary

autocomplete.ts

import { Context } from "koa";
import { PickFromListField } from "../fields/pick-from-list";
import { FormDataValue } from "../form";
import { FormControlContext } from "./form-control";
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(fctx: FormControlContext) {
return {
...(await super.getInputAttributes(fctx)),
list: this.getListID(),
};
}
async postInput(ctx: Context) {
return /* HTML */ `<datalist id="${this.getListID()}">
${(await this.field.generateOptions(ctx)).map(
({ value }) => /* HTML */ `<option>${value}</option>`
)}
</datalist>`;
}
}

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:48 (22 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
645302
Default Alt Text
autocomplete.ts (884 B)

Event Timeline