Skip to content

Commit d3aeb0d

Browse files
committed
fix(filefield): fix bad value in generated targets
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 575dbf8 commit d3aeb0d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

inc/fields/filefield.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ public function deserializeValue($value) {
7171
if ($this->uploadData === null) {
7272
$this->uploadData = [];
7373
}
74-
if (count($this->uploadData) === 0) {
74+
$this->value = __('No attached document', 'formcreator');;
75+
if (count($this->uploadData) > 0) {
7576
$this->value = __('Attached document', 'formcreator');
76-
} else {
77-
$this->value = '';
7877
}
7978
}
8079

tests/suite-unit/PluginFormcreatorFileField.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,23 @@ public function testIsPrerequisites() {
3939
$output = $instance->isPrerequisites();
4040
$this->boolean($output)->isEqualTo(true);
4141
}
42+
43+
public function testDeserializeValue() {
44+
$instance = $this->newTestedInstance([]);
45+
$instance->deserializeValue('invalid Json');
46+
$this->string($instance->getValueForTargetText(true))
47+
->isEqualTo('No attached document');
48+
49+
$instance->deserializeValue('[]');
50+
$this->string($instance->getValueForTargetText(true))
51+
->isEqualTo('No attached document');
52+
53+
$instance->deserializeValue('[1]');
54+
$this->string($instance->getValueForTargetText(true))
55+
->isEqualTo('Attached document');
56+
57+
$instance->deserializeValue('[1,2]');
58+
$this->string($instance->getValueForTargetText(true))
59+
->isEqualTo('Attached document');
60+
}
4261
}

0 commit comments

Comments
 (0)