Component
Description
The adate (approximate date) question type has three bugs that make it unusable: year selection is impossible, toggling "Unknown" after entering a value doesn't persist, and navigating away then back throws an error.
Details
- Year input impossible: Always occurs. The
handleYearChange regex /^\d{4}$/ rejects any partial input ("2", "20", "202"), so a year can never be typed.
- "Unknown" checkbox doesn't write
??: Occurs when checking "Unknown" after a value is already entered (only way to enter a valid date is by pressing "today" to get year filled).
Steps to Reproduce
- Open a form with an adate question
- Try to type a year: nothing is accepted
- Select a month, then check the "Unknown" checkbox for that month: the stored value does not change to
??
Expected Behavior
- User can select a year
- Checking "Unknown" after entering a value stores
?? in the date component
Actual Behavior
- Year field rejects all input
- "Unknown" checkbox has no effect on stored data when toggled after a value is entered
Environment
Component version/branch: dev branch
Additional Context
Root cause for all three bugs is the updateFormData useCallback pattern - it captures stale state when called synchronously after setState. Fix is replacing it with a reactive useEffect that syncs to the form on state change, plus refs to prevent circular updates between the init and sync effects.
In my opinion dropdowns would be a better fit here since day, month, and year are all fixed lists of options. That also removes the year typing problem entirely.