-
-
Save tazeverywhere/b9a72b70ec1a75ed0cce4aa0fdfdd78a to your computer and use it in GitHub Desktop.
Livewire + Choices.js
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
| @props([ | |
| 'placeholder' => null, | |
| ]) | |
| <div | |
| wire:ignore | |
| x-data="{ | |
| value: $wire.entangle(@js($attributes->wire('model')->value)){{ $attributes->wire('model')->hasModifier('live') ? '.live' : '' }}, | |
| init () { | |
| const choices = new Choices(this.$refs.select, { | |
| placeholderValue: @js($placeholder) | |
| }) | |
| choices.setChoiceByValue(this.value); | |
| this.$refs.select.addEventListener('change', () => { | |
| this.value = choices.getValue(true); | |
| }) | |
| }, | |
| }" | |
| > | |
| <select x-ref="select" {{ $attributes->only('multiple') }}> | |
| {{ $slot }} | |
| </select> | |
| </div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment