Skip to content

Commit

Permalink
properly handle empty TagList formwidget
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Dec 10, 2024
1 parent 47307c7 commit 8e54454
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 2 additions & 0 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ protected function hydrateRelationSaveValue($names): ?array
$names = [$names];
}

$names = array_filter($names);

$relation = $this->getRelationObject();
$relationModel = $this->getRelationModel();

Expand Down
1 change: 1 addition & 0 deletions modules/backend/formwidgets/taglist/partials/_taglist.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
value="<?= $field->value ?>">
<?php endif ?>
<?php else: ?>
<input type="hidden" name="<?= $field->getName() ?>[]">
<select
id="<?= $field->getId() ?>"
name="<?= $field->getName() ?>[]"
Expand Down
6 changes: 1 addition & 5 deletions modules/backend/widgets/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,7 @@ public function getSaveData(): array
// Exclude fields that didn't provide any value
$fieldValue = $this->dataArrayGet($result, $parts, FormField::NO_SAVE_DATA);
if ($fieldValue === FormField::NO_SAVE_DATA) {
if ($widget->getConfig('type') === 'taglist') {
$fieldValue = [];
} else {
continue;
}
continue;
}

// Exclude fields where the widget returns NO_SAVE_DATA
Expand Down

0 comments on commit 8e54454

Please sign in to comment.