I'm facing an issue with implementing Select2 within my Laravel project. I want to set up Select2 to display data options when the $authorized variable is true. Initially, everything works fine, but when I change the $authorized back to true, Select2 does not appear even though it should.
I've tried resetting Select2 after the variable change using JavaScript, but it doesn't seem to work. Here's the code snippet I'm using:
@if ($authorized)
<div class="container mt-4" id="divCreate">
<!-- Form content -->
<div class="col-lg-4 mb-3" id="divSelect" wire:ignore>
<label for="asdf" class="form-label">asdf</label>
<select class="form-select" id="asdf" wire:model="asdf">
<!-- Options will be populated dynamically -->
</select>
</div>
</div>
@endif
<script>
$('#asdf').select2({
dropdownParent: $('#divSelect')
}).on('change', function() {
@this.set('asdf', $(this).val());
});
</script>