I use select2 to style selects. But in livewire I faced a problem that when I change the value it doesn’t change even though the select is set to model
<div class="select2-custom-field select2-without-search">
<select class="form-control height-40" wire:model="interval">
@foreach(AppModelsSavedSearch::listInterval() as $key => $value)
<option {{$key == AppModelsSavedSearch::INTERVAL_WEEK ? 'selected' : ''}} value="{{$key}}">{{$value}}</option>
@endforeach
</select>
</div>
I tried adding onchange="@this.call(‘changeInterval’, $(this).val());", but then the select, after selecting the value, looks like normal.
Can this be fixed?
2
Answers
Have you tried changing how the selected option is defined in the options tag? As the styling shouldn’t normally interfere with livewire assignment to component properties.
I assume you are using Livewire 3
Add a wire:ignore in the outer <div>
or alternatively you can wrap that <div> with an outer <div> containing the wire:ignore attribute:
In this way Livewire will not update the <select> which is already managed by the select2
Then to update the $interval variable you can set it on the frontend side using the $wire object: