Last active
April 13, 2024 22:05
-
-
Save jojomak13/9a05f06501372298c95ddca11c248d77 to your computer and use it in GitHub Desktop.
select2 input with alpinejs and livewire
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(['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/[email protected]/dist/css/tom-select.css" rel="stylesheet"> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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