Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 29ea7e4

Browse files
committed
2.0.0
1 parent 86c14b0 commit 29ea7e4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All notable changes to `laravel-form-components` will be documented in this file
1717
- Add `optionDisplay` slot to `<x-custom-select>` component
1818
- Add `wireListeners` property to `<x-custom-select>` component
1919
- Add `$maxOptions` property to `<x-custom-select>` component
20+
- Add ability for custom select options to be dependent on other custom selects
2021
- Add php 8 support
2122

2223
### Removed

docs/components/custom-select.md

+38
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,44 @@ works for both single and multi-select modes, and provides a clear button next t
189189
<x-custom-select :options="$options" optional />
190190
```
191191

192+
## Dependent Selects
193+
194+
If you have a custom select whose options depend on the selection of another select, or just some kind of condition to be met, you can
195+
livewire events to update the options in the select.
196+
197+
In your component definition, pass in an array of livewire event names the select should listen for:
198+
199+
```html
200+
<x-custom-select :options="$options" :wire-listeners="['some-event-name']" />
201+
```
202+
203+
Now in your livewire component, you just need to emit the event(s) you are passing in to the select whenever the options need to be updated:
204+
205+
```php
206+
<?php
207+
208+
namespace App\Http\Livewire;
209+
210+
use Livewire\Component;
211+
212+
class MyComponent extends Component
213+
{
214+
public function someMethodToBeTriggered()
215+
{
216+
// Retrieve your options based on your component state
217+
$options = [
218+
['value' => 'foo', 'text' => 'bar'],
219+
];
220+
221+
// Emit your event, passing in your options as the payload
222+
$this->emit('some-event-name', $options);
223+
}
224+
}
225+
```
226+
227+
Our JavaScript event listener is expecting an array of options as the payload from the event, so be sure
228+
to pass the event emitter your options.
229+
192230
## Fixed Positioning
193231

194232
By default, the custom select menu is positioned absolutely. In most cases, this should be fine, but there

0 commit comments

Comments
 (0)