From 60a141c9febf4b5bf157ae826c0ec86edafb6c40 Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Wed, 6 Dec 2023 14:14:55 +0000 Subject: [PATCH 1/2] added options to change select requirement --- src/Components/Matrix.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Components/Matrix.php b/src/Components/Matrix.php index 01f64e8..19616ea 100644 --- a/src/Components/Matrix.php +++ b/src/Components/Matrix.php @@ -9,12 +9,16 @@ class Matrix extends CheckboxList { protected string $view = 'zeus-matrix-choice::components.matrix-choice'; - protected array | Closure $columnData = []; + protected array|Closure $columnData = []; - protected array | Closure $rowData = []; + protected array|Closure $rowData = []; protected string $redOrBlue = 'radio'; + protected bool $columnSelectRequired = true; + + protected bool $rowSelectRequired = true; + protected function setUp(): void { parent::setUp(); @@ -22,11 +26,11 @@ protected function setUp(): void $this->rules([ function () { return function (string $attribute, mixed $value, Closure $fail) { - if (blank($value) || count($this->getRowData()) !== count($value)) { + if ($this->rowSelectRequired && (blank($value) || count($this->getRowData()) !== count($value))) { $fail(__('required a selection for each row')); } foreach ($value as $val) { - if (is_array($val) && blank(array_filter($val))) { + if ($this->columnSelectRequired && is_array($val) && blank(array_filter($val))) { $fail(__('required a selection for each row')); } } @@ -77,4 +81,18 @@ public function asCheckbox(): static return $this; } + + public function columnSelectRequired(bool $columnSelectRequired = true): static + { + $this->columnSelectRequired = $columnSelectRequired; + + return $this; + } + + public function rowSelectRequired(bool $rowSelectRequired = true): static + { + $this->rowSelectRequired = $rowSelectRequired; + + return $this; + } } From d0a1d48241f7865965eade06b7b2f0b6753813ca Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Wed, 6 Dec 2023 14:22:56 +0000 Subject: [PATCH 2/2] Removed unnecessary column select requirement --- src/Components/Matrix.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Components/Matrix.php b/src/Components/Matrix.php index 19616ea..41e0323 100644 --- a/src/Components/Matrix.php +++ b/src/Components/Matrix.php @@ -15,8 +15,6 @@ class Matrix extends CheckboxList protected string $redOrBlue = 'radio'; - protected bool $columnSelectRequired = true; - protected bool $rowSelectRequired = true; protected function setUp(): void @@ -30,7 +28,7 @@ function () { $fail(__('required a selection for each row')); } foreach ($value as $val) { - if ($this->columnSelectRequired && is_array($val) && blank(array_filter($val))) { + if ($this->rowSelectRequired && is_array($val) && blank(array_filter($val))) { $fail(__('required a selection for each row')); } } @@ -82,13 +80,6 @@ public function asCheckbox(): static return $this; } - public function columnSelectRequired(bool $columnSelectRequired = true): static - { - $this->columnSelectRequired = $columnSelectRequired; - - return $this; - } - public function rowSelectRequired(bool $rowSelectRequired = true): static { $this->rowSelectRequired = $rowSelectRequired;