我尝试在引导模式中使用select2,代码如下:
超文本:
<div class="modal" id="modalTambahData" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tambah Data Untuk Manajemen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="tambahForm">
<div class="form-group">
<label for="recipient-code" class="col-form-label">Kode: </label>
<input type="text" class="form-control" id="recipient-code" required>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Nama:</label>
<input type="text" class="form-control" id="recipient-name" required>
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Unit:</label>
<select class="form-select" id="selectUnit" data-placeholder="Pilih Unit">
@foreach ($data['availableUnit'] as $availableUnit)
<option value="{{ $availableUnit['id'] }}">{{ $availableUnit['name'] }}</option>
@endforeach
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btnConfirm" form="tambahForm">Tambah data</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batalkan</button>
</div>
</div>
</div>
</div>
然后我加了一个脚本:
var selectUnit = $('#selectUnit');
selectUnit.select2({
theme: "bootstrap-5",
placeholder: selectUnit.data('placeholder'),
dropdownParent: selectUnit.parent()
});
但select2不起作用
我已经尝试了dropdownParent,也初始化了select2,当模态显示,但它也不工作,任何想法?
1条答案
按热度按时间xqkwcwgp1#
尝试替换“dropdownParent:选择带有=〉下拉菜单的Unit.parent()“父代:$('#modalTambah数据')
下面是代码: