feat: add client side validation for file input

This commit is contained in:
log101 2024-07-18 20:00:48 +03:00
parent e7e449a079
commit c6f0d851c2

View File

@ -170,6 +170,24 @@ import Layout from "../layouts/Layout.astro";
return; return;
} }
const inputEl = document.getElementById(
"photo-selector"
) as HTMLInputElement | null;
if (!inputEl) return;
const files = inputEl.files;
if (!files) return;
if (files.length > 0) {
if (files[0].size > 4 * 1024 * 1024) {
inputEl.setCustomValidity("Dosya boyutu 4 MB'den küçük olmalıdır.");
inputEl.reportValidity();
return;
}
}
const submitButton = document.getElementById( const submitButton = document.getElementById(
"submit-button" "submit-button"
) as HTMLButtonElement; ) as HTMLButtonElement;