Skip to content

Instantly share code, notes, and snippets.

@tazeverywhere
Forked from robbinbenard/choices.blade.php
Created June 23, 2025 08:28
Show Gist options
  • Save tazeverywhere/b9a72b70ec1a75ed0cce4aa0fdfdd78a to your computer and use it in GitHub Desktop.
Save tazeverywhere/b9a72b70ec1a75ed0cce4aa0fdfdd78a to your computer and use it in GitHub Desktop.
Livewire + Choices.js
@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