Skip to content

[Formplayer] adate: year input broken, unknown checkbox doesn't persist #354

@arthur-d42

Description

@arthur-d42

Component

  • formulus (React Native mobile app)
  • formulus-formplayer (React web app)
  • synkronus (Go backend server)
  • synkronus-cli (Command-line utility)
  • Documentation
  • Other (please specify)

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

  1. Open a form with an adate question
  2. Try to type a year: nothing is accepted
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions