fix(tapops): clamp year pada input dan change event agar validasi aktif saat mengetik

This commit is contained in:
Dodo
2026-06-04 16:58:05 +07:00
parent edab5db3d7
commit 5bb704ac88
+12 -6
View File
@@ -586,13 +586,19 @@ class DocumentRepository {
if (!input) return;
input.setAttribute('max', '9999-12-31');
input.setAttribute('min', '1000-01-01');
// Clamp year on change as a fallback for browsers that don't enforce max.
input.addEventListener('change', () => {
// Clamp year on both input (fires while typing) and change (fires on blur).
const clampYear = () => {
if (!input.value) return;
const [yearStr, month, day] = input.value.split('-');
const year = parseInt(yearStr, 10);
if (year > 9999) input.value = `9999-${month}-${day}`;
});
const parts = input.value.split('-');
if (parts.length !== 3) return;
const year = parseInt(parts[0], 10);
if (!Number.isNaN(year) && year > 9999) {
parts[0] = '9999';
input.value = parts.join('-');
}
};
input.addEventListener('input', clampYear);
input.addEventListener('change', clampYear);
});
this.searchInput?.addEventListener('input', (e) => {