Skip to content

Commit

Permalink
Merge pull request #18 from dmason30/multiple
Browse files Browse the repository at this point in the history
Adds checkbox multiple support
  • Loading branch information
199ocero authored May 30, 2024
2 parents 0aa1bbe + 6b5911b commit 73e184d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion resources/views/forms/components/radio-deck.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$id = $getId();
$isDisabled = $isDisabled();
$isMultiple = $isMultiple();
$statePath = $getStatePath();
@endphp

Expand All @@ -18,7 +19,9 @@

<label class="flex cursor-pointer gap-x-3">
<input @disabled($shouldOptionBeDisabled) id="{{ $id }}-{{ $value }}"
name="{{ $id }}" type="radio" value="{{ $value }}" wire:loading.attr="disabled"
name="{{ $id }}"
type="{{ $isMultiple ? 'checkbox' : 'radio' }}"
value="{{ $value }}" wire:loading.attr="disabled"
{{ $applyStateBindingModifiers('wire:model') }}="{{ $statePath }}"
{{ $getExtraInputAttributeBag()->class(['peer hidden']) }} />

Expand Down
22 changes: 22 additions & 0 deletions src/Forms/Components/RadioDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JaOcero\RadioDeck\Forms\Components;

use App\Filament\Fields\CheckboxDeck;
use Closure;
use Filament\Support\Concerns\HasAlignment;
use Filament\Support\Concerns\HasColor;
Expand Down Expand Up @@ -36,8 +37,17 @@ class RadioDeck extends IntermediaryRadio

protected array|Arrayable|Closure|string $descriptions = [];

protected bool|Closure $isMultiple = false;

protected string $view = 'radio-deck::forms.components.radio-deck';

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

$this->default(fn (RadioDeck $component): mixed => $component->isMultiple() ? [] : null);
}

public function icons(array|Arrayable|string|Closure|null $icons): static
{
$this->icons = $icons;
Expand All @@ -52,6 +62,13 @@ public function descriptions(array|Arrayable|string|Closure $descriptions): stat
return $this;
}

public function multiple(bool|Closure $condition = true): static
{
$this->isMultiple = $condition;

return $this;
}

/**
* @param array-key $value
*/
Expand Down Expand Up @@ -132,4 +149,9 @@ public function getDescriptions(): array

return $descriptions;
}

public function isMultiple(): bool
{
return (bool) $this->evaluate($this->isMultiple);
}
}

0 comments on commit 73e184d

Please sign in to comment.