document.addEventListener('DOMContentLoaded', function () { const formSetsContainer = document.getElementById('form-sets-container'); const btnTambahForm = document.getElementById('btnTambahForm'); // Auto-expand textarea function autoExpand(textarea) { textarea.addEventListener('input', function () { this.style.height = 'auto'; this.style.height = this.scrollHeight + 'px'; }); } // Inisialisasi Selectize function initSelectizeAll(context = document) { $(context).find('.tags-menu').selectize(selectizeConfigTagsMenu); $(context).find('.date-input').selectize(selectizeConfigDateInput); } // Destroy semua selectize sebelum clone function destroySelectize(context) { context.querySelectorAll('select').forEach(select => { const instance = select.selectize; if (instance) instance.destroy(); }); } // Inisialisasi awal document.querySelectorAll('.auto-expand').forEach(autoExpand); initSelectizeAll(); // Tambah form-set btnTambahForm.addEventListener('click', function () { const lastFormSet = formSetsContainer.querySelector('.form-set:last-of-type'); // Destroy selectize sebelum clone destroySelectize(lastFormSet); const clone = lastFormSet.cloneNode(true); // Bersihkan input dan textarea clone.querySelectorAll('input, textarea').forEach(el => { if (el.type === 'file') { el.value = null; } else { el.value = ''; } }); // Bersihkan select (hapus .selectize dan reset element