Page MenuHomeSealhub

file.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
import { Context } from "koa";
import { FileContainer } from "../fields/file";
import { FormDataValue } from "../form";
import { SimpleInput } from "./simple-input";
export class File extends SimpleInput<FileContainer> {
getType() {
return "file";
}
async preInput(ctx: Context, data: Record<string, FormDataValue>) {
const { parsed } = await this.field.getValue(ctx, data);
return /* HTML */ ` ${parsed.old?.filename || ""}
<input
type="hidden"
name="${this.field.name}[old][id]"
value="${parsed.old?.id || ""}"
/>
<input
type="hidden"
name="${this.field.name}[old][filename]"
value="${parsed.old?.filename || ""}"
/>`;
}
async getInputAttributes(
ctx: Context,
data: Record<string, FormDataValue>,
field_prefix: string,
form_id: string
) {
const original = await super.getInputAttributes(
ctx,
data,
field_prefix,
form_id
);
const { parsed } = await this.field.getValue(ctx, data);
return {
...original,
name: this.field.name + "[new]",
required: original.required && !parsed.old,
value: false,
onchange:
(original.onchange || "") +
";" +
"filename = this.value.split('\\\\').slice(-1)[0]; this.parentElement.style.setProperty('--filename', '\\'Wybrany plik: ' + filename + '\\'')",
};
}
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 16:28 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200645
Default Alt Text
file.ts (1 KB)

Event Timeline