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

Single field validation does not run on fields when loading the form #628

Closed
Tracked by #339 ...
olemartinorg opened this issue Nov 7, 2022 · 4 comments
Closed
Tracked by #339 ...
Labels
area/validation related to form validation rules/messages fe-v4 Issues to be solved before v4 goes gold kind/bug Something isn't working

Comments

@olemartinorg
Copy link
Contributor

olemartinorg commented Nov 7, 2022

Description of the bug

If you're loading existing instance data, fields may appear valid even though single field validation would have marked it as invalid. This is because app-frontend will not run single field validation on fields that hasn't been changed in any way - it will just assume validation was successful.

To fix this, we might have to run server-side validation as soon as we load the instance (possibly only if instance data was found).

Steps To Reproduce

  1. Open the frontend-test app
  2. Type test in the first name field, it gives an error
  3. Refresh the page, the error is gone until you try to submit the form

Attempted fix

When fixing #617, I tried fixing this problem at the same time, but my solution was problematic. What I did was extending the saga for checkIfConditionalRulesShouldRun to run FormLayoutActions.updateCurrentView to update the current view to the current view (hacky!) while telling it to run page validations (and I added a parameter to skip empty field validations). This way validations would run when the page loads (because the saga for checkIfConditionalRulesShouldRun runs after the page loads, and after dynamically hidden fields have been hidden when the page loads).

However, this leads to a breaking change (as single field validations can be set up to complain when required data is missing, and running that on the page load is quite user hostile). I found this solution kind-of hacky, so maybe this should be considered in relation to #339 (where we should investigate if we want our app to keep its state after a refresh, or if we can live with an app that behaves differently after a refresh).

@olemartinorg olemartinorg added the kind/bug Something isn't working label Nov 7, 2022
@olemartinorg olemartinorg added the fe-v4 Issues to be solved before v4 goes gold label Sep 25, 2023
@RonnyB71
Copy link
Member

RonnyB71 commented Oct 3, 2023

Alternative 1
Single field validation should run when loading the form if there are values in the field. This does not solve the case where you would like to validate if one of x number of fields have a value but not the others.

Alternative 2
Trigger validation even if there is no data. This implies marking the single field validation as a "required" validation.

Alternative 3
Include a datatype for internal state and validations on each component. This is probably not doable for V4, but might be the preferred solution. This needs more discussion.

@RonnyB71
Copy link
Member

RonnyB71 commented Nov 3, 2023

Will be solved by #1506

@RonnyB71 RonnyB71 mentioned this issue Nov 22, 2023
Closed
@olemartinorg
Copy link
Contributor Author

Isn't this essentially solved now, @bjosttveit? Not by running single field validation, but by gathering all validations and showing then on load.

@bjosttveit
Copy link
Member

Yes this should no longer be an issue

@olemartinorg olemartinorg moved this to ✅ Done in Team Apps Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/validation related to form validation rules/messages fe-v4 Issues to be solved before v4 goes gold kind/bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants