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

AddressNL validation triggers #789

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

robinmolen
Copy link
Contributor

Part of open-formulieren/open-forms#4699

Making sure that the addressNL frontend validation is only triggered when the component is dirty and after losing focus from any of it's fields.

Copy link

codecov bot commented Jan 29, 2025

Bundle Report

Changes will increase total bundle size by 240 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@open-formulieren/sdk-OpenForms-umd 4.77MB 120 bytes (0.0%) ⬆️
@open-formulieren/sdk-esm 4.75MB 120 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @open-formulieren/sdk-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/formio-*.js 120 bytes 2.03MB 0.01%

Files in assets/formio-*.js:

  • ./src/formio/components/AddressNL.jsx → Total Size: 13.97kB
view changes for bundle: @open-formulieren/sdk-OpenForms-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
open-*.js 120 bytes 3.49MB 0.0%

Files in open-*.js:

  • ./src/formio/components/AddressNL.jsx → Total Size: 13.99kB

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 62.86%. Comparing base (263df05) to head (b16552c).

Files with missing lines Patch % Lines
src/formio/components/AddressNL.jsx 9.09% 10 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (263df05) and HEAD (b16552c). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (263df05) HEAD (b16552c)
storybook 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #789       +/-   ##
===========================================
- Coverage   83.65%   62.86%   -20.79%     
===========================================
  Files         244      237        -7     
  Lines        4777     4139      -638     
  Branches     1268      748      -520     
===========================================
- Hits         3996     2602     -1394     
- Misses        748     1316      +568     
- Partials       33      221      +188     
Flag Coverage Δ
storybook ?
vitest 62.86% <9.09%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

…er dirty

To trigger the validation once the addressNL component has changed, we have to monitor formik changes. Using the `dirty` property from the `useFormikContext` we can simplify this monitoring. Unfortunately we can only set/alter the validation on the top level. With this we have three options:

- We can add `onBlur` properties to all addressNL fields. This means that we can handle formValidation after blur, and only when `dirty === true`. This would add a lot of custom properties and logic, for a small 'problem'. This would also move us futher from a "the component functions on its own" way of working.
- We can add `onBlur` eventListeners via `useEffect`. This would give us the same functionality as the previous option, without all the custom properties. It would also make the addressNL component even more complex and introduce unexpected behavior.
- Finally we can change the validation rule based on the `dirty` property. For this to work, we would have to pass the `dirty` prop to the parent component, to then change the validation rule. It is a strange way to work, but would mean the least amount of custom behavior and keep the validation process understandable.

For simplicity sake, I've chosen the last option. To use the `dirty` prop from the formik context to change the addressNL component validation
@robinmolen robinmolen force-pushed the issue/4699-addressNL-validation-triggers branch from e321f06 to b16552c Compare January 30, 2025 08:59
@robinmolen robinmolen marked this pull request as ready for review January 30, 2025 09:00
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.

1 participant