Skip to content

Commit

Permalink
Merge pull request #3 from ArtDepartmentMJ/optional-selects
Browse files Browse the repository at this point in the history
Optional selects
  • Loading branch information
atmonshi authored Dec 6, 2023
2 parents bd8c8e7 + d0a1d48 commit d7abfa1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Components/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ 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 $rowSelectRequired = true;

protected function setUp(): void
{
parent::setUp();

$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->rowSelectRequired && is_array($val) && blank(array_filter($val))) {
$fail(__('required a selection for each row'));
}
}
Expand Down Expand Up @@ -77,4 +79,11 @@ public function asCheckbox(): static

return $this;
}

public function rowSelectRequired(bool $rowSelectRequired = true): static
{
$this->rowSelectRequired = $rowSelectRequired;

return $this;
}
}

0 comments on commit d7abfa1

Please sign in to comment.