diff --git a/packages/ecc-utils-design/src/components/form/form.ts b/packages/ecc-utils-design/src/components/form/form.ts index 6fae36f3..aa07a5b7 100644 --- a/packages/ecc-utils-design/src/components/form/form.ts +++ b/packages/ecc-utils-design/src/components/form/form.ts @@ -164,12 +164,12 @@ export default class EccUtilsDesignForm extends LitElement { private handleTusFileUpload = async ( e: Event, field: Field - ): Promise => { + ): Promise | null> => { const file = (e.target as HTMLInputElement).files?.[0]; if (!file) { console.error("No file selected for upload."); - return; + return null; } try { @@ -194,11 +194,20 @@ export default class EccUtilsDesignForm extends LitElement { this.requestUpdate(); }, onSuccess: () => { + const data: any = { + url: upload.url, + file, + name: "", + }; + if ("name" in upload.file) { console.log("Download %s from %s", upload.file.name, upload.url); + data.name = upload.file.name; } else { console.log("Download file from %s", upload.url); } + + return data; }, }); @@ -211,6 +220,8 @@ export default class EccUtilsDesignForm extends LitElement { } catch (error) { console.error("An error occurred while initializing the upload:", error); } + + return null; }; renderInputTemplate(field: Field, path: string): TemplateResult { @@ -248,7 +259,12 @@ export default class EccUtilsDesignForm extends LitElement { class="file-input" ?disabled=${field.fieldOptions?.readonly} @change=${async (e: Event) => { - await this.handleTusFileUpload(e, field); + const data = await this.handleTusFileUpload(e, field); + + if (data) { + _.set(this.form, path, data); + this.alertFieldChange(field.key, data); + } }} />