Did you include Select2 JS and CSS files ?
Dec 9, 2021
27
Level 6
Select2 not working on the child component
I have to component table and form when I run the test in the table(Parent) component the select2 is working but when I run the test in the form(Child) component form it will not run.
Test Select in the table and form
<div class="form-group">
<label class="col-sm-3 control-label" for="customer_id">Country</label>
<div class="col-sm-9">
<select id="ex" class="form-control" data-placeholder="Choose a Country..." id="demo-chosen-select" tabindex="2">
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Aland Islands">Aland Islands</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Yemen">Yemen</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
</div>
</div>
I just include the javascript file the the table(Parent) component
@section('custom_script')
@include('layouts.scripts.job-order-scripts');
@endsection
and this is my script
$(function(){
$('#ex').select2();
});
Should I make another script to attached in the form(Child) component?
Level 6
@Sinnbeck Thanks sir I already fixed it.... I just put it in event and called when the modal open
document.addEventListener("DOMContentLoaded", () => {
Livewire.on('select2', postId => {
$('#customer').select2({
dropdownParent: $("#joborderModal")
});//
})
}
Please or to participate in this conversation.