From 0892cee293a8e4e0d80dff85e2364e1eada8cb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Wed, 21 Feb 2024 23:31:59 +0100 Subject: [PATCH] Set enum required if value is not empty string --- src/Controls/CheckboxListEnum.php | 2 +- src/Controls/RadioListEnum.php | 2 +- src/Controls/SelectBoxEnum.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controls/CheckboxListEnum.php b/src/Controls/CheckboxListEnum.php index bfd53d0..4ddd1f6 100644 --- a/src/Controls/CheckboxListEnum.php +++ b/src/Controls/CheckboxListEnum.php @@ -65,7 +65,7 @@ public function setValue(/*?LabeledEnum*/ $values): self $values = Arrays::map($values, function(mixed $value) { if (isset($value) && !$value instanceof $this->enumType) { - $value = $this->enumType::make($value); + $value = $this->enumType::make($value, $value !== ''); } return $value?->value; diff --git a/src/Controls/RadioListEnum.php b/src/Controls/RadioListEnum.php index a90caa0..25057f6 100644 --- a/src/Controls/RadioListEnum.php +++ b/src/Controls/RadioListEnum.php @@ -60,7 +60,7 @@ public function setItems(array $enums, bool $useKeys = true): self public function setValue(/*?LabeledEnum*/ $value): self { if (isset($value) && !$value instanceof $this->enumType) { - $value = $this->enumType::make($value); + $value = $this->enumType::make($value, $value !== ''); } return parent::setValue($value?->value ?? null); diff --git a/src/Controls/SelectBoxEnum.php b/src/Controls/SelectBoxEnum.php index b879f8d..4f6b205 100644 --- a/src/Controls/SelectBoxEnum.php +++ b/src/Controls/SelectBoxEnum.php @@ -55,7 +55,7 @@ public function setItems(array $enums, bool $useKeys = true, bool $badge = false public function setValue(/*?LabeledEnum*/ $value): self { if (isset($value) && !$value instanceof $this->enumType) { - $value = $this->enumType::make($value); + $value = $this->enumType::make($value, $value !== ''); } return parent::setValue($value?->value ?? null);