Skip to content

Instantly share code, notes, and snippets.

@jojomak13
Last active April 13, 2024 22:05
Show Gist options
  • Save jojomak13/9a05f06501372298c95ddca11c248d77 to your computer and use it in GitHub Desktop.
Save jojomak13/9a05f06501372298c95ddca11c248d77 to your computer and use it in GitHub Desktop.
select2 input with alpinejs and livewire
@props(['multiple' => false])
<div {{ $attributes }} wire:ignore x-data="{
value: @entangle($attributes->wire('model')),
init(){
let input = new TomSelect(this.$refs.select, {
onChange: (value) => this.value = value,
items: this.value
});
}
}">
<select x-ref="select" {{ $multiple? 'multiple' : '' }} x-model="value">
{{ $slot }}
</select>
</div>
<link href="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/css/tom-select.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/js/tom-select.complete.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment