Page MenuHomeSealhub

number.ts
No OneTemporary

number.ts

import { Context } from "koa";
import { FlatTemplatable } from "tempstream";
import { FormField, NumberField } from "../fields/field";
import { FormDataValue } from "../form";
import { SimpleInput, SimpleInputOptions } from "./simple-input";
export type NumberOptions = SimpleInputOptions &
Partial<{ step: number; suffix: string }>;
export class Number extends SimpleInput<number | null> {
field: NumberField;
options: NumberOptions;
constructor(field: NumberField, options: NumberOptions) {
super(field, options);
}
getType() {
return "number";
}
async postInput(_: Context): Promise<FlatTemplatable> {
return this.options.suffix
? /* HTML */ `<span class="suffix">${this.options.suffix}</span>`
: "";
}
async getInputAttributes(
ctx: Context,
data: Record<string, FormDataValue>,
field_prefix: string,
form_id: string
): Promise<Record<string, string | boolean>> {
const original = await super.getInputAttributes(
ctx,
data,
field_prefix,
form_id
);
return {
...original,
...Object.fromEntries([
...(this.field.options.min
? [["min", this.field.options.min]]
: []),
...(this.field.options.max
? [["max", this.field.options.max]]
: []),
...(this.options.step ? [["step", this.options.step]] : []),
]),
};
}
}

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:39 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
645332
Default Alt Text
number.ts (1 KB)

Event Timeline