Fix vfs customfield for single file did not replace when you chose a different file from VFS

This commit is contained in:
nathan 2024-10-24 11:37:04 -06:00
parent 23fb0dcdd8
commit 1612ddb030
3 changed files with 8 additions and 3 deletions

View File

@ -963,10 +963,11 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
const value = typeof e.target.value == "string" ? [e.target.value] : e.target.value; const value = typeof e.target.value == "string" ? [e.target.value] : e.target.value;
value.forEach(v => value.forEach(v =>
{ {
const info = e.target._dialog.fileInfo(v); const info = {...e.target._dialog.fileInfo(v)};
if(!e.target.multiple) if(!e.target.multiple)
{ {
info.name = field.name; info.name = field.name;
info.path = "/apps/" + e.target.methodId.replaceAll(":", "/");
} }
e.target.getParent().getWidgetById(attrs.id)?._addFile(info); e.target.getParent().getWidgetById(attrs.id)?._addFile(info);
}); });

View File

@ -648,7 +648,7 @@ export class et2_vfsUpload extends et2_file
for(var child_index = this._children.length-1; child_index >= 0; child_index--) for(var child_index = this._children.length-1; child_index >= 0; child_index--)
{ {
var child = this._children[child_index]; var child = this._children[child_index];
if(child.options.value.path === file_data.path) if(!child.options.value || child.options.value.path === file_data.path)
{ {
this.removeChild(child); this.removeChild(child);
child.destroy(); child.destroy();

View File

@ -316,7 +316,11 @@ class Link extends Etemplate\Widget
{ {
if(!str_ends_with($dest_file, '/') && count($files) == 1) if(!str_ends_with($dest_file, '/') && count($files) == 1)
{ {
// 1 file to a specific filename // 1 file to a specific filename, overwrite if already there
if(file_exists(Api\Link::vfs_path($app, $id)))
{
unlink(Api\Link::vfs_path($app, $id));
}
Api\Vfs::symlink($files[0], Api\Link::vfs_path($app, $id)); Api\Vfs::symlink($files[0], Api\Link::vfs_path($app, $id));
} }
else else