Skip to content

Commit

Permalink
Fix MultiSelect when empty selection is given
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg committed Dec 20, 2023
1 parent e1069ca commit c1624b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion protected/humhub/modules/ui/form/widgets/BasePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function beforeRun()
*/
public function run()
{
if ($this->selection != null && !is_array($this->selection)) {
if ($this->selection !== null && !is_array($this->selection)) {
$this->selection = [$this->selection];
}

Expand Down
6 changes: 4 additions & 2 deletions protected/humhub/modules/ui/form/widgets/MultiSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace humhub\modules\ui\form\widgets;

use yii\helpers\ArrayHelper;

/**
* Multiselect
*
Expand Down Expand Up @@ -51,7 +53,7 @@ protected function getItemKey($item)

protected function getSelectedOptions()
{
if (empty($this->selection)) {
if ($this->selection === null) {
$attribute = $this->attribute;
$this->selection = ($this->model) ? $this->model->$attribute : [];
}
Expand All @@ -66,7 +68,7 @@ protected function getSelectedOptions()
continue;
}

$result[$key] = $this->buildItemOption([$key => $value], in_array($key, $this->selection));
$result[$key] = $this->buildItemOption([$key => $value], ArrayHelper::keyExists($key, $this->selection));
}
return $result;
}
Expand Down

0 comments on commit c1624b5

Please sign in to comment.