Created
December 4, 2024 16:47
-
-
Save robbinbenard/5ce47b409228cd9fe1ab0aa2937c4d13 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