diff --git a/public/js/dashboard/action.js b/public/js/dashboard/action.js index 17a791b..3cfe60f 100644 --- a/public/js/dashboard/action.js +++ b/public/js/dashboard/action.js @@ -48,23 +48,21 @@ renderFileList(inputId, container); } - formCreate.on('submit', function(e){ + formCreate.off('submit').on('submit', function(e){ e.preventDefault(); - - let hasFile = false; - for (const inputId in allFiles) { - if(allFiles[inputId] && allFiles[inputId].length > 0){ - hasFile = true; - break; - } - } - + const submitBtn = $(this).find('button[type="submit"]'); + submitBtn.prop('disabled', true).text('menyimpan...') + let hasFile = Object.keys(allFiles).every(id => { + console.log('fil ' , allFiles[id],' length', allFiles[id].length > 0); + return Array.isArray(allFiles[id]) && allFiles[id].length > 0; + }); if(!hasFile){ Swal.fire({ icon: 'warning', title: 'Perhatian', text: 'Silahkan upload minimal 1 file sebelum submit' }); + submitBtn.prop('disabled', false).text('Simpan') return; } const formData = new FormData(this); @@ -93,24 +91,28 @@ color: "#fff", } }).showToast(); - $("#col_add_file").html(''); - colCount = 1; // reset counter - formCreate.find('input[type="file"]').each(function () { + allFiles = []; + formCreate.find('input[type="file"].file-input').each(function () { const newInput = $(this).clone(); // clone dengan attribute multiple $(this).replaceWith(newInput); // ganti input lama dengan baru bindFileUpload(newInput[0]) - }); + // console.log(newInput); + }); + colCount = 1; + $("#col_add_file").html('') formCreate.find('select').val(null).trigger('change'); document.querySelectorAll(".file-name").forEach(el => { el.classList.add("d-none"); el.innerHTML = ""; }); + if($("#klasifikasi_dok").val().length === 0 || $("#kategori_dok").val().length === 0 ){ index() }else{ searchData() } + submitBtn.prop('disabled', false).text('Simpan') modalCreate.removeEventListener('hidden.bs.modal', handler); }; modalCreate.addEventListener('hidden.bs.modal', handler); @@ -126,6 +128,7 @@ title: 'Gagal', text: err.message }); + submitBtn.prop('disabled', false).text('Simpan...') } }); }); diff --git a/public/js/dashboard/functions.js b/public/js/dashboard/functions.js index c4becb9..9c7153b 100644 --- a/public/js/dashboard/functions.js +++ b/public/js/dashboard/functions.js @@ -116,7 +116,7 @@ function addForm(){