Pengaduan
Form Pengaduan Wali Murid
Sampaikan pertanyaan, keluhan, kritik, maupun saran
kepada pihak sekolah secara tertib dan santun.
(function() {
const form = document.getElementById("formPengaduan");
const judul = document.getElementById("judul"); const isi = document.getElementById("isiPengaduan");
const judulCount = document.getElementById("judulCount"); const isiCount = document.getElementById("isiCount");
const fileInput = document.getElementById("lampiran"); const fileInfo = document.getElementById("fileInfo");
const btnSubmit = document.getElementById("btnSubmit");
const successMessage = document.getElementById("successMessage");
const nomorPengaduan = document.getElementById("nomorPengaduan");
/* ========================== COUNTER ========================== */
judul.addEventListener("input", function() { judulCount.textContent = this.value.length; });
isi.addEventListener("input", function() { isiCount.textContent = this.value.length; });
/* ========================== FILE CHECK ========================== */
fileInput.addEventListener("change", function() {
fileInfo.innerHTML = "";
if (!this.files.length) { return; }
const file = this.files[0];
const maxSize = 2 * 1024 * 1024;
const allowedTypes = [ "image/jpeg", "image/png", "application/pdf" ];
if (!allowedTypes.includes(file.type)) {
alert( "Format file tidak diperbolehkan. " + "Gunakan JPG, PNG atau PDF." );
this.value = "";
return; }
if (file.size > maxSize) {
alert( "Ukuran file terlalu besar. " + "Maksimal ukuran file adalah 2 MB." );
this.value = "";
return; }
const size = (file.size / 1024).toFixed(1);
fileInfo.innerHTML = "✓ File dipilih: " + file.name + " (" + size + " KB)";
});
/* ========================== GENERATE NOMOR ========================== */
function generateNomorPengaduan() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
const random = Math.floor(1000 + Math.random() * 9000);
return "PENG-" + year + month + day + "-" + random; }
/* ========================== SUBMIT ========================== */
form.addEventListener("submit", function(e) {
e.preventDefault();
/* VALIDASI */
const requiredFields = form.querySelectorAll("[required]");
let valid = true;
requiredFields.forEach(function(field) {
field.classList.remove("input-error");
if ( (field.type === "checkbox" && !field.checked) || (field.type !== "checkbox" && !field.value.trim()) ) {
field.classList.add("input-error");
valid = false; }
});
if (!valid) {
alert( "Mohon lengkapi semua data yang wajib diisi." );
const firstError = form.querySelector(".input-error");
if (firstError) { firstError.focus(); }
return; }
/* NOMOR PENGADUAN */
const nomor = generateNomorPengaduan();
nomorPengaduan.textContent = nomor;
/* SIMULASI PROSES */
btnSubmit.disabled = true;
btnSubmit.innerHTML = "⏳ Mengirim Pengaduan...";
setTimeout(function() {
form.style.display = "none";
successMessage.style.display = "block";
btnSubmit.disabled = false;
btnSubmit.innerHTML = "📨 Kirim Pengaduan";
}, 1200);
});
})();
/* ============================== PENGADUAN BARU ================================= */
function buatPengaduanBaru() {
const form = document.getElementById("formPengaduan");
const success = document.getElementById("successMessage");
form.reset();
document.getElementById("judulCount").textContent = "0";
document.getElementById("isiCount").textContent = "0";
document.getElementById("fileInfo").innerHTML = "";
document.querySelectorAll(".input-error") .forEach(function(el) { el.classList.remove("input-error"); });
success.style.display = "none";
form.style.display = "block";
window.scrollTo({ top: document.getElementById( "pengaduan-wali-murid" ).offsetTop - 30, behavior: "smooth" });
}