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

Frontend does not ignore required validations from backend #1062

Closed
ivarne opened this issue Mar 29, 2023 · 4 comments
Closed

Frontend does not ignore required validations from backend #1062

ivarne opened this issue Mar 29, 2023 · 4 comments
Labels
area/validation related to form validation rules/messages kind/bug Something isn't working org/srf Issues relevant for Statens sivilrettforvaltning

Comments

@ivarne
Copy link
Member

ivarne commented Mar 29, 2023

Description of the bug

Apps that enable "RemoveHiddenDataPreview" gets the benefit of backend validation of components that are marked "required": true (or an expression that evaluates to true). This is great because it ensures that users that open devtools, or deliver schema using the API, also is forced to answer all the required questions before submitting.

A problem is that backend during validation does not know what language the user wants their messages, so it can't really say anything more than required and indicate the field and component that triggered the error. I suggest to improve it somewhat in Altinn/app-lib-dotnet#217, but as frontend already generates great warnings for empty required fields, the result will always be a duplicated validation message. I think the best solution is to just ignore any validation error with "code": "required" so that frontend can handle required independent of backend. (there probably need to be some way to show the error in case frontend thinks the instance is OK, but backend still thinks required values are missing).

image

Steps To Reproduce

  1. Enable "RemoveHiddenDataPreview"
  2. Add components with "required" to the schema
  3. Trigger validation with empty required components
  4. See that you get double error messages for required where one just states TODO required

Additional Information

No response

@ivarne ivarne added the kind/bug Something isn't working label Mar 29, 2023
@olemartinorg olemartinorg added the area/validation related to form validation rules/messages label Mar 30, 2023
@RonnyB71 RonnyB71 added the org/srf Issues relevant for Statens sivilrettforvaltning label Mar 31, 2023
@ivarne
Copy link
Member Author

ivarne commented Apr 11, 2023

@RonnyB71 @olemartinorg I'd like to be able to resolve this mess with TODO required showing up in frontend, because I feel it has my name written all over it. Any ideas/preferences?

I currently see a few possible solutions:

  1. Add default translation text for TODO required, or just change the text to remove TODO (easy, but does not solve the problem that frontend also does this validation, and it causes duplicate errors for users.)
  2. Ignore "code": "required" validations in frontend in redux. (there would need to be some way to show the errors before submitting in case the validation in frontend works differently and OK in frontend fails in backend.)
  3. Be intelligent in frontend on display, and ensure that only a single required validation is shown to the user, and obviously prefer the pretty client side one with proper translation and included question text.

@olemartinorg
Copy link
Contributor

I'd prefer number 2 as a temporary solution, but with that said, the whole validations system is due for an overhaul (and I think the plan is to start discussing solutions there very soon). I think it's better to look into the whole problem area instead of playing whack-a-mole with every bug in this category right now.

@olemartinorg
Copy link
Contributor

Workaround has been manually tested and verified to work. 🥳 Thanks!

@olemartinorg
Copy link
Contributor

I think it's time to close this one, and live with the workaround we already have. It is even less temporary now than it was back when we started talking about it as temporary.. 😉

As for the overhaul: Altinn/app-template-dotnet#180

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 kind/bug Something isn't working org/srf Issues relevant for Statens sivilrettforvaltning
Projects
Archived in project
Development

No branches or pull requests

3 participants