Skip to content

Commit

Permalink
Issue: Create Task File Upload
Browse files Browse the repository at this point in the history
This commit fixes an issue where attachments were not being added if you tried to create a Task and populate a custom File Upload field. getClean() would return an empty array, so there was no information that could be used to create the attachment record.
  • Loading branch information
aydreeihn committed Jul 30, 2020
1 parent 741122a commit 87f5006
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/ajax.tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function add($tid=0, $vars=array()) {
if ($desc
&& $desc->isAttachmentsEnabled()
&& ($attachments=$desc->getWidget()->getAttachments()))
$vars['files'] = $attachments->getFiles();
$vars['files'] = $attachments->getFiles();
$vars['staffId'] = $thisstaff->getId();
$vars['poster'] = $thisstaff;
$vars['ip_address'] = $_SERVER['REMOTE_ADDR'];
Expand Down
13 changes: 12 additions & 1 deletion include/class.dynamic_forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,18 @@ function saveAnswers($isEditable=null, $refetch=false) {

try {
$field->setForm($this);
$val = $field->to_database($field->getClean());
//for form entry values of file upload fields, we want to save the value as
//json with the file id(s) and file name(s) of each file stored in the field
//so that they display correctly within tasks/tickets
if (get_class($field) == 'FileUploadField') {
//use getChanges if getClean returns an empty array
$fieldClean = $field->getClean() ?: $field->getChanges();
if (is_array($fieldClean) && $fieldClean[0])
$fieldClean = json_decode($fieldClean[0], true);
} else
$fieldClean = $field->getClean();

$val = $field->to_database($fieldClean);
}
catch (FieldUnchanged $e) {
// Don't update the answer.
Expand Down

0 comments on commit 87f5006

Please sign in to comment.