Select2 Multiple select using Livewire



Selected Tasks : None

This is a free component. Login to your account to view / download the component code.

Component Class


namespace App\Http\Livewire;

use App\Models\DummyTask;
use Livewire\Component;

class Select2Multiple extends Component
    public $tasks = [];
    public $selectedTasks = [];

    public function render()
        return view('livewire.select2-multiple');

    public function mount(){
        $this->tasks = DummyTask::all();

Component View File

    <div wire:ignore>
        <label for="taskSelect" class="form-label">Select Tasks</label>
        <select class="form-select" id="taskSelect" multiple="multiple" >
            @foreach($tasks as $task)
                <option id="{{$task->id}}">{{$task->title}}</option>
    <div class="my-3">
        Selected Tasks : 
        @forelse($selectedTasks as $task)
        $(document).ready(function() {

            $('#taskSelect').on('change', function (e) {
                @this.set('selectedTasks', $(this).val());




To use select2 plugin, make sure you include its CSS and JS library in your project.

    <link href="" rel="stylesheet" />
    <script src="" defer></script>   </script>

The javascript code is straighftforward. We initialize select2 box on the taskSelect input, and on the change event we call the set event of livewire which sets the desired input field with the value of select2 box.

Make sure you mark you select box with wire:ignore directive, this will make sure livewire does not repaints the input on reload, since we don't want to loose select2 classes and selected values.

Download Code

Download the Component class, view file and other required files

Please login to download the component code