Skip to content

Commit

Permalink
Additional fix for validation of hidden fields in non-repeating groups (
Browse files Browse the repository at this point in the history
#82)

* Also making sure not to check for required fields when the field (even if inside a group) is hidden

* Bumping version

* Yikes, I'm working on too many branches at once. Revert!

* Bumping version

* Bumping version again

Co-authored-by: Ole Martin Handeland <git@olemartin.org>
  • Loading branch information
olemartinorg and Ole Martin Handeland authored May 10, 2022
1 parent 11f787c commit c5fe348
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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

0 comments on commit c5fe348

Please sign in to comment.