Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong type for validation properties #4018

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

sergei-maertens
Copy link
Member

Closes #4016

The fix is two-fold:

  • Update frontend code to ensure that Formio's bad default values are stripped out
  • Add data migration + import conversion to fix bad existing data

Formio uses empty strings for length-indication defaults in the
validation configuration (minLength, maxLength, min, max, minWords,
maxWords) which leaks into textfield, number and derived components
like email, phone number...

This is wrong for a number of reasons:

1. Semantically you'd expect undefined or null, not an empty string
2. Comparing string with a number to perform validation crashes the
   backend
3. Their own typescript types are defined as 'maxLength?: number',
   stating that it's either undefined or a number.

Using 'null' will cause us typescript issues, so the patch targets
these invalid defaults and deletes the keys alltogether, which results
in:

1. it being 'undefined' in the frontend code, which should pass the
   falsy checks
2. the missing key in the backend will default to 'None', which is
   explicitly checked.

This only applies to new components, existing data needs a data
migration to correct this.
The invalid validate keys are dropped from the existing configuration.

This patch also ensures that old form imports are automatically patched
up during import.
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.03%. Comparing base (571b1ae) to head (757b9fb).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4018   +/-   ##
=======================================
  Coverage   96.02%   96.03%           
=======================================
  Files         728      728           
  Lines       22792    22801    +9     
  Branches     2636     2639    +3     
=======================================
+ Hits        21887    21896    +9     
  Misses        649      649           
  Partials      256      256           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sergei-maertens sergei-maertens merged commit 8b6ff27 into master Mar 19, 2024
27 checks passed
@sergei-maertens sergei-maertens deleted the issue/4016-wrong-maxlength-type branch March 19, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to submit a form with a textfield without max length specified
2 participants