diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a14035..c61b59b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `livewire-filters` will be documented in this file. +## 0.3 - 2022-03-05 + +- Added `getOptionId` method for better handling of setting an option's ID attribute when dealing with associative arrays +- Added `getOptionName` method for better handling of setting an option's name attribute when dealing with associative arrays +- Added `getOptionValue` method for better handling of setting an option's value when dealing with associative arrays + ## 0.2 - 2022-02-28 - Added the `meta` field to `Filter` class diff --git a/composer.json b/composer.json index f7a084b..9608dd9 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "kirschbaum-development/livewire-filters", - "description": "This is my package livewire-filters", + "description": "Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.", "keywords": [ "kirschbaum-development", "laravel", @@ -19,6 +19,7 @@ "require": { "php": "^8.0", "illuminate/contracts": "^9.0", + "illuminate/support": "^9.0", "livewire/livewire": "^2.10", "spatie/laravel-package-tools": "^1.9.2" }, diff --git a/resources/views/checkbox-filter.blade.php b/resources/views/checkbox-filter.blade.php index e3cc2f2..08b8f41 100644 --- a/resources/views/checkbox-filter.blade.php +++ b/resources/views/checkbox-filter.blade.php @@ -1,16 +1,16 @@
- @foreach ($options as $option) + @foreach ($options as $id => $option)
- +
@endforeach
diff --git a/resources/views/radio-filter.blade.php b/resources/views/radio-filter.blade.php index 9b9c11b..2781a74 100644 --- a/resources/views/radio-filter.blade.php +++ b/resources/views/radio-filter.blade.php @@ -1,16 +1,16 @@
- @foreach ($options as $option) + @foreach ($options as $id => $option)
- +
@endforeach
diff --git a/resources/views/select-filter.blade.php b/resources/views/select-filter.blade.php index 4d4d882..40101b9 100644 --- a/resources/views/select-filter.blade.php +++ b/resources/views/select-filter.blade.php @@ -1,7 +1,7 @@
diff --git a/src/FilterComponent.php b/src/FilterComponent.php index 322b6ef..b88d7d2 100644 --- a/src/FilterComponent.php +++ b/src/FilterComponent.php @@ -2,6 +2,7 @@ namespace Kirschbaum\LivewireFilters; +use Illuminate\Support\Arr; use Livewire\Component; abstract class FilterComponent extends Component @@ -33,6 +34,25 @@ public function resetValue(): void $this->emitFilterEvent(); } + public function getOptionId($value): string + { + return $this->key . '-' . strtolower(str_replace(' ', '_', $value)); + } + + public function getOptionName($value): string + { + return $this->key . '-' . strtolower(str_replace(' ', '_', $value)); + } + + public function getOptionValue($id, $value): mixed + { + if (Arr::isAssoc($this->options)) { + return $id; + } + + return $value; + } + public function updatedValue(): void { $this->emitFilterEvent(); diff --git a/src/Filters/RadioFilter.php b/src/Filters/RadioFilter.php index ecf2c89..fd86058 100644 --- a/src/Filters/RadioFilter.php +++ b/src/Filters/RadioFilter.php @@ -6,6 +6,11 @@ class RadioFilter extends FilterComponent { + public function getOptionName($value): string + { + return $this->key; + } + public function render() { return view('livewire-filters::radio-filter');