<div class="fv-row mb-7" wire:ignore>
<!--begin::Label-->
<label class="required fw-semibold fs-6 mb-2">Category</label>
<!--end::Label-->
<!--begin::Input-->
<select name="category_id" aria-label="Select a Category" data-control="select2" wire:model.defer="category_id"
class="form-select form-select-solid fw-bold category_id">
<option value="">Select a Category...</option>
@foreach($this->categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach
</select>
<!--end::Input-->
</div>
<div class="fv-row mb-7" wire:ignore>
<!--begin::Label-->
<label class="required fw-semibold fs-6 mb-2">Sub-Category</label>
<!--end::Label-->
<!--begin::Input-->
<select name="child_category_id" aria-label="Select a Sub-Category" data-control="select2" wire:model.defer="child_category_id"
class="form-select form-select-solid fw-bold child_category_id">
<option value="">Select a Sub-Category...</option>
@foreach($sub_categories as $sub)
<option value="{{$sub->id}}">{{$sub->name}}</option>
@endforeach
</select>
<!--end::Input-->
</div>
@push("scripts")
<script>
$(document).ready(function () {
var $selectElementCategory = $(".category_id");
$selectElementCategory.on("change", function (e) {
var data_category = $selectElementCategory.val();
@this.set("category_id", data_category);
});
var $selectElement = $(".child_category_id");
$selectElement.on("change", function (e) {
var data = $selectElement.val();
@this.set("child_category_id", data);
});
})
</script>
@endpush
public function updatedCategoryId()
{
$this->sub_categories = Category::whereParentId($this->category_id)->get();
}
You can try initializing Select2 within the Bootstrap modal event. Here's a revised approach:
Initialize Select2 within the Bootstrap modal event for when the modal is fully loaded.
$("#your-modal").on("shown.bs.modal", function () {
$("#your-select-element").select2();
});
nothing changes the same problem, when the select outside modal it works fine but the problem inside the modal, and inside the modal when edit the option chosen not selected just marked as true
Hi,
Please check this link for the updated select2.
https://gist.github.com/faizalmy/243ef00e9d9059429c5b27e10fe67176
Search Input Focus Issue:
The select2() method is called on both the category_id and child_category_id dropdowns during the livewire:load event. This initializes Select2 properly.
Child Category Update Issue:
The wire:ignore directive has been removed from the child_category_id div to allow Livewire to manage the element.
The select2() method is now applied to the child_category_id dropdown, enabling it to work with Select2 and update correctly when category_id changes.
Let us know if any issue. Thanks
this is inside modal