Skip to content

Commit a43d96d

Browse files
committed
✨ Add select all in multi select filters
Signed-off-by: Julio Renzi C. Motol <[email protected]>
1 parent aa96fbe commit a43d96d

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

resources/views/bootstrap-4/includes/filter-type-multiselect.blade.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
<div class="form-check">
2+
<input
3+
class="form-check-input"
4+
onclick="event.stopPropagation();"
5+
type="checkbox"
6+
id="filter-{{$key}}-select-all"
7+
wire:input="selectAllFilters('{{ $key }}')"
8+
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
9+
>
10+
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
11+
</div>
112
@foreach($filter->options() as $optionKey => $value)
213
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
314
<input

resources/views/bootstrap-5/includes/filter-type-multiselect.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<div class="form-check">
2+
<input
3+
onclick="event.stopPropagation();"
4+
type="checkbox"
5+
id="filter-{{$key}}-select-all"
6+
wire:input="selectAllFilters('{{ $key }}')"
7+
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
8+
>
9+
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
10+
</div>
111
@foreach($filter->options() as $optionKey => $value)
212
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
313
<input

resources/views/tailwind/includes/filter-type-multiselect.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<div class="mt-1 relative rounded-md">
2+
<div>
3+
<input
4+
type="checkbox"
5+
id="filter-{{$key}}-select-all"
6+
wire:input="selectAllFilters('{{ $key }}')"
7+
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
8+
>
9+
<label for="filter-{{$key}}-select-all">@lang('All')</label>
10+
</div>
211
@foreach($filter->options() as $optionKey => $value)
312
<div wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
413
<input

src/Traits/WithFilters.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ public function cleanFilters(): void
196196
})->toArray();
197197
}
198198

199+
public function selectAllFilters($filterKey): void
200+
{
201+
$filter = $this->filters()[$filterKey];
202+
203+
if (! $filter->isMultiSelect()) {
204+
return;
205+
}
206+
207+
if (count($this->filters[$filterKey]) === count($filter->options())) {
208+
$this->removeFilter($filterKey);
209+
return;
210+
}
211+
212+
$this->filters[$filterKey] = array_keys($filter->options());
213+
}
214+
199215
/**
200216
* Define the string location to a view to be included as the filters view
201217
*

0 commit comments

Comments
 (0)