Skip to content

Commit

Permalink
Merge branch 'master' into fix/FIO-8723_clearing_default_values_for_h…
Browse files Browse the repository at this point in the history
…idden_components
  • Loading branch information
brendanbond committed Sep 10, 2024
2 parents 8c9d8a0 + 5030b37 commit bce8283
Show file tree
Hide file tree
Showing 24 changed files with 1,423 additions and 298 deletions.
22 changes: 22 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
## [Unreleased: 2.3.0-rc.2]
### Changed
- Regression | Nested Form | Components in Nested forms should not validate hidden components without Validate When Hidden = true
- FIO-8807: fixed an issue where conditionals based on selectBoxes component do not work
- FIO-8778: add case for map component model type in filter; add tests
- FIO-8347: Added ability to skip mask validation
- FIO-8731: Update fix to nested hidden components
- FIO-8731: Fixes component gets validated when being in a hidden parent
- FIO-8273 fixed advanced logic for data components
- FIO-8730: Fix submission has hidden fields when 'Clear value when hidden' is checked
- FIO-8626: Updated conditionally hidden logic
- FIO-7733: update most form params to optional
- fixing child components being displayed when they should be removed when clearOnHide is set
- FIO-8639 fixed validation for select component if onlyAvailableItems is set to false
- FIO-8645: added tests and translations for validateRequiredDay
- FIO-8537: Fixing the filter processor to handle nested component data properly
- FIO-8597: fixed an issue with an empty array value for a number component with multiple values enabled
- FIO-8798: updated day component validation
- FIO-8885 & FIO-8886: use strict equality check for conditional component paths rather than Array.prototype.includes
- FIO-8810: fixed an issue where user unables to resubmit (change) the form with several levels of nested forms with required fields
- FIO-8848 fixed validation for TextArea with Save as Json
- FIO-8769 added check for the simpleConditional properties state
- FIO-8901: Fixed incorrect handling of excessive rows in nested array model
- FIO-8912: update validateMultiple to account for model types
- fix formiojs tests

## 2.3.0-rc.1
### Changed
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
"dependencies": {
"@types/json-logic-js": "^2.0.7",
"browser-cookies": "^1.2.0",
"core-js": "^3.37.1",
"dayjs": "^1.11.11",
"dompurify": "^3.1.4",
"core-js": "^3.38.0",
"dayjs": "^1.11.12",
"dompurify": "^3.1.6",
"eventemitter3": "^5.0.0",
"fast-json-patch": "^3.1.1",
"fetch-ponyfill": "^7.1.0",
"inputmask": "5.0.8",
"json-logic-js": "^2.0.2",
"inputmask": "5.0.9",
"json-logic-js": "^2.0.5",
"lodash": "^4.17.21",
"moment": "^2.29.4"
},
Expand Down
13 changes: 11 additions & 2 deletions src/experimental/base/array/__tests__/ArrayComponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,32 @@ describe('ArrayComponent', () => {
{
firstName: 'Sally',
lastName: 'Thompson'
},
{
firstName: 'Jane',
lastName: 'Doe'
}
];
arrComp.dataValue = employees;
assert.deepEqual(data, {employees: employees});
assert.deepEqual(arrComp.dataValue, employees);
assert.equal(arrComp.rows.length, 2);
assert.equal(arrComp.rows.length, 3);
assert.equal(arrComp.rows[0].length, 2);
assert.equal(arrComp.rows[1].length, 2);
assert.equal(arrComp.components.length, 4);
assert.equal(arrComp.rows[2].length, 2);
assert.equal(arrComp.components.length, 6);
assert.equal(arrComp.components[0].dataValue, 'Joe');
assert.equal(arrComp.components[1].dataValue, 'Smith');
assert.strictEqual(arrComp.rows[0][0], arrComp.components[0]);
assert.strictEqual(arrComp.rows[0][1], arrComp.components[1]);
assert.strictEqual(arrComp.rows[1][0], arrComp.components[2]);
assert.strictEqual(arrComp.rows[1][1], arrComp.components[3]);
assert.strictEqual(arrComp.rows[2][0], arrComp.components[4]);
assert.strictEqual(arrComp.rows[2][1], arrComp.components[5]);
assert.equal(arrComp.components[2].dataValue, 'Sally');
assert.equal(arrComp.components[3].dataValue, 'Thompson');
assert.equal(arrComp.components[4].dataValue, 'Jane');
assert.equal(arrComp.components[5].dataValue, 'Doe');

// Ensure it removes rows.
employees = [
Expand Down
4 changes: 2 additions & 2 deletions src/experimental/model/NestedArrayModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function NestedArrayModel(props: any = {}) : ModelDecoratorInterface {

// Remove superfluous rows.
if (dataValue.length > value.length) {
for (let i = value.length; i < dataValue.length; i++) {
for (let i = dataValue.length - 1; i >= value.length; i--) {
this.removeRow(i);
}
}
Expand Down Expand Up @@ -192,4 +192,4 @@ export function NestedArrayModel(props: any = {}) : ModelDecoratorInterface {
}
}
}
};
};
91 changes: 91 additions & 0 deletions src/process/__tests__/fixtures/forDataGridRequired.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"form": {
"name": "dsf",
"path": "dsf",
"type": "form",
"display": "form",
"components": [
{
"label": "Data Grid",
"reorder": false,
"addAnotherPosition": "bottom",
"layoutFixed": false,
"enableRowGroups": false,
"initEmpty": false,
"tableView": false,
"defaultValue": [
{}
],
"validate": {
"required": true
},
"validateWhenHidden": false,
"key": "dataGrid",
"type": "datagrid",
"input": true,
"components": [
{
"label": "Columns",
"columns": [
{
"components": [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validateWhenHidden": false,
"key": "textField",
"type": "textfield",
"input": true
}
],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0,
"size": "md",
"currentWidth": 6
},
{
"components": [],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0,
"size": "md",
"currentWidth": 6
}
],
"key": "columns",
"type": "columns",
"input": false,
"tableView": false
}
]
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
],
"created": "2024-08-07T08:41:53.926Z",
"modified": "2024-08-07T08:41:53.932Z",
"machineName": "tbtzzegecytgzpi:dsf"
},
"submission": {
"data": {

"dataGrid": [
{
"textField": ""
}
],
"submit": true
}

}
}
3 changes: 2 additions & 1 deletion src/process/__tests__/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import clearOnHideWithHiddenParent from './clearOnHideWithHiddenParent.json';
import skipValidForConditionallyHiddenComp from './skipValidForConditionallyHiddenComp.json';
import skipValidForLogicallyHiddenComp from './skipValidForLogicallyHiddenComp.json';
import skipValidWithHiddenParentComp from './skipValidWithHiddenParentComp.json';
import forDataGridRequired from './forDataGridRequired.json';
import data1a from './data1a.json';
import form1 from './form1.json';
import subs from './subs.json';

export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForLogicallyHiddenComp, skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, data1a, form1, subs };
export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForLogicallyHiddenComp, skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, forDataGridRequired, data1a, form1, subs };
120 changes: 119 additions & 1 deletion src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from 'node:assert'
import type { ContainerComponent, ValidationScope } from 'types';
import { getComponent } from 'utils/formUtil';
import { process, processSync, ProcessTargets } from '../index';
import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, skipValidWithHiddenParentComp } from './fixtures'
import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, forDataGridRequired, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, skipValidWithHiddenParentComp } from './fixtures'
/*
describe('Process Tests', () => {
it('Should perform the processes using the processReduced method.', async () => {
Expand Down Expand Up @@ -2827,6 +2827,103 @@ describe('Process Tests', () => {
});
})

it('Should allow the submission to go through without errors if there is no the subform reference value', async () => {
const form = {
_id: '66bc5cff7ca1729623a182db',
title: 'form2',
name: 'form2',
path: 'form2',
type: 'resource',
display: 'form',
owner: '637b2e6b48c1227e60b1f910',
components: [
{
label: 'Text Field - form2',
applyMaskOn: 'change',
tableView: true,
validate: { required: true },
validateWhenHidden: false,
key: 'textFieldForm2',
type: 'textfield',
input: true,
},
{
label: 'Form',
tableView: true,
form: '66bc5ccd7ca1729623a18063',
useOriginalRevision: false,
key: 'form',
type: 'form',
input: true,
components: [
{
label: 'Text Field form1',
applyMaskOn: 'change',
tableView: true,
validate: { required: true },
validateWhenHidden: false,
key: 'textFieldForm1',
type: 'textfield',
input: true,
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
project: '669e1c67a40e327e67e7ce55',
_vid: 0,
esign: {},
created: '2024-08-14T07:30:07.953Z',
modified: '2024-08-14T10:09:13.201Z',
machineName: 'qzdhayddccjauyr:form2',
__v: 1,
};

const submission = {
data: { textFieldForm2: '1', form: { _id: '66c455fc0f00757fd4b0e79b' } },
owner: '637b2e6b48c1227e60b1f910',
access: [],
_fvid: 0,
state: 'submitted',
_id: '66c455fc0f00757fd4b0e79d',
form: '66bc5cff7ca1729623a182db',
};

const errors: any = [];
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: { errors },
config: {
server: true,
},
};
processSync(context);
submission.data = context.data;
context.processors = ProcessTargets.evaluator;
processSync(context);
assert.equal(context.scope.errors.length, 0);
assert.deepEqual(context.data.form, { _id: '66c455fc0f00757fd4b0e79b', data: {} })
});

describe('Required component validation in nested form in DataGrid/EditGrid', () => {
const nestedForm = {
key: 'form',
Expand Down Expand Up @@ -3087,6 +3184,27 @@ describe('Process Tests', () => {
});
});

it('Should validate when all child components are empty in required Data Grid', async () => {
const { form, submission } = forDataGridRequired;
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};

processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);

expect((context.scope as ValidationScope).errors).to.have.length(1);
});

describe('For EditGrid:', () => {
const components = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/process/clearHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) =

// Check if there's a conditional set for the component and if it's marked as conditionally hidden
const isConditionallyHidden = (scope as ConditionsScope).conditionals?.find((cond) => {
return path.includes(cond.path) && cond.conditionallyHidden;
return path === cond.path && cond.conditionallyHidden;
});

const shouldClearValueWhenHidden = !component.hasOwnProperty('clearOnHide') || component.clearOnHide;
Expand Down
Loading

0 comments on commit bce8283

Please sign in to comment.