You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m not sure if there’s a way to do this, but I’d really like to make my field “dumb”.
For some reason, if the user enters an incorrect date—for example, typing 13 as the month—it automatically adds a month as part of its calculation.
I don’t need this kind of calculation. I just want to let the user type a date, and if they enter an invalid format or a value outside the allowed range, show an error or revert to the previous value.
Any ideas?
constinput=document.getElementById('date');consterror=document.getElementById('date-error');flatpickr(input,{dateFormat: 'Y-m-d',allowInput: true,parseDate(text){constmatch=/^(\d{4})-(\d{2})-(\d{2})$/.exec(text);if(!match)returnundefined;const[,year,month,day]=match.map(Number);constdate=newDate(0);date.setHours(0,0,0,0);date.setFullYear(year,month-1,day);returndate.getFullYear()===year&&date.getMonth()===month-1&&date.getDate()===day ? date : undefined;},errorHandler(){error.textContent='Enter a valid date as YYYY-MM-DD.';}});input.addEventListener('input',()=>{error.textContent='';});
I tested manual input followed by blur in Chromium with the built Flatpickr editor. Month 13, April 31, February 29 in 2025, and trailing text are rejected; February 29 in 2024 and April 30 are accepted. In this configuration rejected input clears the selection and shows the inline message; it does not restore the previous date.
This example accepts only the displayed format above. If you use a different altFormat, the custom parser must also handle that format. Calendar validity is separate from application-specific allowed dates, which should remain configured through options such as minDate, maxDate or disable.
Activity
sridharkalaibala commentedon Sep 13, 2026
You can reject calendar rollover through the existing
parseDateoption. For an exactY-m-dinput, validate the components after constructing the date:I tested manual input followed by blur in Chromium with the built Flatpickr editor. Month 13, April 31, February 29 in 2025, and trailing text are rejected; February 29 in 2024 and April 30 are accepted. In this configuration rejected input clears the selection and shows the inline message; it does not restore the previous date.
This example accepts only the displayed format above. If you use a different
altFormat, the custom parser must also handle that format. Calendar validity is separate from application-specific allowed dates, which should remain configured through options such asminDate,maxDateordisable.