75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
$(document).ready(function() {
|
|
selectOptionPegawai(0)
|
|
});
|
|
|
|
function selectOptionPegawai(colCount) {
|
|
let selectPegawai = $(`#pegawai_id_${colCount}`);
|
|
// inisialisasi select2 untuk Unit Kerja
|
|
selectPegawai.select2({
|
|
placeholder: '-- Pilih Pegawai --',
|
|
allowClear:true,
|
|
width: '100%',
|
|
dropdownParent: selectPegawai.parent(),
|
|
ajax:{
|
|
url : '/select-pegawai',
|
|
dataType: 'json',
|
|
delay: 250,
|
|
data: function(params){
|
|
return { q: params.term }
|
|
},
|
|
processResults: function(data){
|
|
return {
|
|
results : data?.data.map(item => ({
|
|
id: item.id,
|
|
text: item.nama,
|
|
}))
|
|
}
|
|
},
|
|
cache: true,
|
|
},
|
|
minimumInputLength: 1,
|
|
});
|
|
}
|
|
|
|
|
|
|
|
let colCount = 1;
|
|
function addForm(){
|
|
let col = $("#col_add_akses")
|
|
|
|
let html = '';
|
|
|
|
html += `
|
|
<div class="row mt-3" id="col-${colCount}">
|
|
<hr/>
|
|
<div class="col-md-6 mb-2">
|
|
<label>Nama</label>
|
|
<select class="form-control" name="data[${colCount}][pegawai_id]" id="pegawai_id_${colCount}" required>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4 mb-2">
|
|
<label>Akses</label>
|
|
<select class="form-control" name="data[${colCount}][akses]" id="akses_id_${colCount}" required>
|
|
<option value="" disable>Select Choose</option>
|
|
<option value="all">Semua Akses</option>
|
|
<option value="unit">By Unit Akses</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="button" class="btn btn-danger mt-3 me-2" onclick="removeCol(${colCount})"><i class="fa-solid fa-trash"></i></button>
|
|
</div>
|
|
|
|
</div>
|
|
`
|
|
col.append(html)
|
|
selectOptionPegawai(colCount)
|
|
colCount++;
|
|
|
|
}
|
|
|
|
|
|
function removeCol(count){
|
|
$(`#col-${count}`).remove()
|
|
}
|
|
|