Update file field

How to prevent a file field from being cleared during form edits.

Overview

The issue occurs because the edit form empties the file field when no new file is uploaded, deleting the existing record.
To solve this, modify the data handling to check if the file field is empty during the edit process and preserve the existing file data accordingly.

Answered
Connectivity v6
ce cesarvelame 12 Jan, 2021
Hi, I have this file field "arquivo" in a CC6 form and works very well to create new records, but the edit works wrong. The edit form empty the file field record when is not filled.

I tried this code in a function before saving data with no success:
if(empty($this->data["arquivo"])){
unset($this->data["arquivo"]);
}

I tried this too:
$new_data = $this->data;
if(empty($this->data["arquivo"])){
unset($new_data["arquivo"]);
}
$this->set("new", $new_data);
{var:new} as the data provider, but no success.

Can anyone send a tip?

Thanks
ce cesarvelame 12 Jan, 2021
Answer
Solved:
$this->data["doc"]["arquivo"] = $this->data["arquivo"];
if(empty($this->data["doc"]["arquivo"])){
unset($this->data["doc"]["arquivo"]);
}
This topic is locked and no more replies can be posted.