Created
September 12, 2024 05:52
-
-
Save sprobejames/92634680a6b54b3dbf62c8389c9eb2ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| <x-multi-select | |
| model="some_public_property" | |
| class="select-custom" | |
| placeholderValue="Select all you want" | |
| :options="[['label' => 'FOO', 'value' => 'foo'], ['label' => 'BAR', 'value' => 'bar']]" | |
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| @props(['options' => [], 'placeholderValue' => '', 'model']) | |
| @php | |
| $uniqId = 'select' . uniqid(); | |
| @endphp | |
| <div wire:ignore | |
| x-data | |
| x-init=" | |
| $nextTick(() => { | |
| const choices = new Choices($refs.{{ $uniqId }}, { | |
| removeItems: true, | |
| removeItemButton: true, | |
| placeholderValue: '{{ $placeholderValue }}', | |
| }) | |
| })" | |
| > | |
| <select | |
| x-ref="{{ $uniqId }}" | |
| wire:change="$set('{{ $model }}', [...$event.target.options].filter(option => option.selected).map(option => option.value))" | |
| {{ $attributes }} | |
| multiple | |
| > | |
| @foreach($options as $option) | |
| <option value="{{ $option['value'] }}">{{ $option['label'] }}</option> | |
| @endforeach | |
| </select> | |
| </div> | |
| @pushOnce('styles') | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css"/> | |
| @endPushOnce | |
| @pushOnce('scripts') | |
| <script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script> | |
| @endPushOnce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment