Skip to content

Commit

Permalink
Merge pull request #2743 from bolt/bugfix/imagelist-filelist-can-be-d…
Browse files Browse the repository at this point in the history
…eleted

`imagelist` and `filelist` fields can be emptied
  • Loading branch information
bobdenotter committed Aug 6, 2021
2 parents c387131 + b7bb9e0 commit f214cbd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions assets/js/app/editor/Components/Filelist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@moveFileDown="onMoveFileDown"
></editor-file>
</div>
<div v-if="containerFiles.length === 0">
<input :name="name" value="" type="hidden" />
</div>

<button class="btn btn-tertiary" type="button" :disabled="!allowMore" @click="addFile">
<i class="fas fa-fw fa-plus"></i>
Expand Down Expand Up @@ -104,9 +107,6 @@ export default {
onRemoveFile(elem) {
let fieldNumber = this.getFieldNumberFromElement(elem);
this.containerFiles.splice(fieldNumber, 1);
if (this.containerFiles.length === 0) {
this.addFile();
}
},
fieldName(index) {
return this.name + '[' + index + ']';
Expand Down
7 changes: 3 additions & 4 deletions assets/js/app/editor/Components/Imagelist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@moveImageDown="onMoveImageDown"
></editor-image>
</div>
<div v-if="getActiveImageFields().length === 0">
<input :name="name" value="" type="hidden" />
</div>

<button class="btn btn-tertiary" type="button" :disabled="!allowMore" @click="addImage">
<i class="fas fa-fw fa-plus"></i>
Expand Down Expand Up @@ -114,10 +117,6 @@ export default {
let updatedImage = this.containerImages[fieldNumber];
updatedImage.hidden = true;
this.$set(this.containerImages, fieldNumber, updatedImage);
if (this.getActiveImageFields().length === 0) {
this.addImage();
}
},
fieldName(index) {
return this.name + '[' + index + ']';
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/Field/FilelistField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class FilelistField extends Field implements FieldInterface, ListFieldInterface,
*/
public function getRawValue(): array
{
return (array) parent::getValue() ?: [];
$value = parent::getValue();

return empty(current($value)) ? [] : (array) $value;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/Field/ImagelistField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ImagelistField extends Field implements FieldInterface, ListFieldInterface
*/
public function getRawValue(): array
{
return (array) parent::getValue() ?: [];
$value = parent::getValue();

return empty(current($value)) ? [] : (array) $value;
}

/**
Expand Down

0 comments on commit f214cbd

Please sign in to comment.