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

Additional fix for validation of hidden fields in non-repeating groups #82

Merged
merged 7 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/altinn-app-frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altinn-app-frontend",
"version": "3.36.3",
"version": "3.36.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/altinn-app-frontend/src/utils/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,13 @@ describe('utils > validation', () => {
simpleBinding: { errors: ['Feltet er påkrevd'], warnings: [] },
};

it('should skip validation on required field in hidden group', () => {
it('should pass validation on required field in hidden group', () => {
expect(_with({hiddenFields: ['group_simple']})[requiredFieldInSimpleGroup]).toBeUndefined();
});
it('should run validation on required field in visible group', () => {
it('should pass validation on required field in group, when field itself is hidden', () => {
expect(_with({hiddenFields: [requiredFieldInSimpleGroup]})[requiredFieldInSimpleGroup]).toBeUndefined();
});
it('should mark as required with required field in visible group', () => {
expect(_with({hiddenFields: []})[requiredFieldInSimpleGroup]).toEqual(requiredError);
});

Expand Down
3 changes: 2 additions & 1 deletion src/altinn-app-frontend/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ export function validateEmptyFieldsForLayout(
const componentsToCheck = formLayout.filter((component) => {
return (
(component as ILayoutComponent).required &&
childrenWithoutMultiPagePrefix(group).indexOf(component.id) > -1
childrenWithoutMultiPagePrefix(group).indexOf(component.id) > -1 &&
!hiddenFields.includes(component.id)
);
});

Expand Down