Skip to content

Commit 916f30c

Browse files
$'syncing commit from monorepo. PR: 359, Title: FIO-10346: Fixes an issue where logical change of required property was concidered only if it was added by logic, but not when it was removed by it' (#285)
Co-authored-by: TanyaGashtold <TanyaGashtold@users.noreply.github.com>
1 parent 37944d7 commit 916f30c

4 files changed

Lines changed: 290 additions & 2 deletions

File tree

src/process/__tests__/fixtures/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import form1 from './form1.json';
1212
import subs from './subs.json';
1313
import requiredFieldInsideEditGrid from './requiredFieldInsideConditionalEditGrid.json';
1414
import formWithDefaultValues from './componentsWithDefaultValues.json';
15+
import requiredValidationDisabledByLogic from './requiredValidationDisabledByLogic.json';
1516

1617
export {
1718
addressComponentWithOtherCondComponents,
@@ -28,4 +29,5 @@ export {
2829
subs,
2930
requiredFieldInsideEditGrid,
3031
formWithDefaultValues,
32+
requiredValidationDisabledByLogic,
3133
};
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
{
2+
"type": "form",
3+
"display": "form",
4+
"components": [
5+
{
6+
"label": "B",
7+
"applyMaskOn": "change",
8+
"tableView": true,
9+
"validate": {
10+
"required": true,
11+
"custom": "",
12+
"customPrivate": false,
13+
"strictDateValidation": false,
14+
"multiple": false,
15+
"unique": false,
16+
"minLength": "",
17+
"maxLength": "",
18+
"pattern": ""
19+
},
20+
"validateWhenHidden": false,
21+
"key": "b",
22+
"logic": [
23+
{
24+
"name": "Skip Required",
25+
"trigger": {
26+
"type": "simple",
27+
"simple": {
28+
"show": true,
29+
"conjunction": "all",
30+
"conditions": [
31+
{
32+
"component": "skipRequired",
33+
"operator": "isEqual",
34+
"value": true
35+
}
36+
]
37+
}
38+
},
39+
"actions": [
40+
{
41+
"name": "Skip Required",
42+
"type": "property",
43+
"property": {
44+
"label": "Required",
45+
"value": "validate.required",
46+
"type": "boolean"
47+
},
48+
"state": false
49+
}
50+
]
51+
}
52+
],
53+
"type": "textfield",
54+
"input": true,
55+
"id": "evjjdls",
56+
"placeholder": "",
57+
"prefix": "",
58+
"customClass": "",
59+
"suffix": "",
60+
"multiple": false,
61+
"defaultValue": null,
62+
"protected": false,
63+
"unique": false,
64+
"persistent": true,
65+
"hidden": false,
66+
"clearOnHide": true,
67+
"refreshOn": "",
68+
"redrawOn": "",
69+
"modalEdit": false,
70+
"dataGridLabel": false,
71+
"labelPosition": "top",
72+
"description": "",
73+
"errorLabel": "",
74+
"tooltip": "",
75+
"hideLabel": false,
76+
"tabindex": "",
77+
"disabled": false,
78+
"autofocus": false,
79+
"dbIndex": false,
80+
"customDefaultValue": "",
81+
"calculateValue": "",
82+
"calculateServer": false,
83+
"widget": {
84+
"type": "input"
85+
},
86+
"attributes": {},
87+
"validateOn": "change",
88+
"conditional": {
89+
"show": null,
90+
"when": null,
91+
"eq": ""
92+
},
93+
"overlay": {
94+
"style": "",
95+
"left": "",
96+
"top": "",
97+
"width": "",
98+
"height": ""
99+
},
100+
"allowCalculateOverride": false,
101+
"encrypted": false,
102+
"showCharCount": false,
103+
"showWordCount": false,
104+
"properties": {},
105+
"allowMultipleMasks": false,
106+
"addons": [],
107+
"serverOverride": {},
108+
"mask": false,
109+
"inputType": "text",
110+
"inputFormat": "plain",
111+
"inputMask": "",
112+
"displayMask": "",
113+
"spellcheck": true,
114+
"truncateMultipleSpaces": false
115+
},
116+
{
117+
"label": "Skip Required",
118+
"tableView": false,
119+
"validateWhenHidden": false,
120+
"key": "skipRequired",
121+
"type": "checkbox",
122+
"input": true,
123+
"defaultValue": false,
124+
"id": "eoz059n",
125+
"placeholder": "",
126+
"prefix": "",
127+
"customClass": "",
128+
"suffix": "",
129+
"multiple": false,
130+
"protected": false,
131+
"unique": false,
132+
"persistent": true,
133+
"hidden": false,
134+
"clearOnHide": true,
135+
"refreshOn": "",
136+
"redrawOn": "",
137+
"modalEdit": false,
138+
"dataGridLabel": true,
139+
"labelPosition": "right",
140+
"description": "",
141+
"errorLabel": "",
142+
"tooltip": "",
143+
"hideLabel": false,
144+
"tabindex": "",
145+
"disabled": false,
146+
"autofocus": false,
147+
"dbIndex": false,
148+
"customDefaultValue": "",
149+
"calculateValue": "",
150+
"calculateServer": false,
151+
"widget": null,
152+
"attributes": {},
153+
"validateOn": "change",
154+
"validate": {
155+
"required": false,
156+
"custom": "",
157+
"customPrivate": false,
158+
"strictDateValidation": false,
159+
"multiple": false,
160+
"unique": false
161+
},
162+
"conditional": {
163+
"show": null,
164+
"when": null,
165+
"eq": ""
166+
},
167+
"overlay": {
168+
"style": "",
169+
"left": "",
170+
"top": "",
171+
"width": "",
172+
"height": ""
173+
},
174+
"allowCalculateOverride": false,
175+
"encrypted": false,
176+
"showCharCount": false,
177+
"showWordCount": false,
178+
"properties": {},
179+
"allowMultipleMasks": false,
180+
"addons": [],
181+
"serverOverride": {},
182+
"inputType": "checkbox",
183+
"value": "",
184+
"name": ""
185+
},
186+
{
187+
"type": "button",
188+
"label": "Submit",
189+
"key": "submit",
190+
"disableOnInvalid": true,
191+
"input": true,
192+
"tableView": false,
193+
"id": "e19px9p",
194+
"placeholder": "",
195+
"prefix": "",
196+
"customClass": "",
197+
"suffix": "",
198+
"multiple": false,
199+
"defaultValue": null,
200+
"protected": false,
201+
"unique": false,
202+
"persistent": false,
203+
"hidden": false,
204+
"clearOnHide": true,
205+
"refreshOn": "",
206+
"redrawOn": "",
207+
"modalEdit": false,
208+
"dataGridLabel": true,
209+
"labelPosition": "top",
210+
"description": "",
211+
"errorLabel": "",
212+
"tooltip": "",
213+
"hideLabel": false,
214+
"tabindex": "",
215+
"disabled": false,
216+
"autofocus": false,
217+
"dbIndex": false,
218+
"customDefaultValue": "",
219+
"calculateValue": "",
220+
"calculateServer": false,
221+
"widget": {
222+
"type": "input"
223+
},
224+
"attributes": {},
225+
"validateOn": "change",
226+
"validate": {
227+
"required": false,
228+
"custom": "",
229+
"customPrivate": false,
230+
"strictDateValidation": false,
231+
"multiple": false,
232+
"unique": false
233+
},
234+
"conditional": {
235+
"show": null,
236+
"when": null,
237+
"eq": ""
238+
},
239+
"overlay": {
240+
"style": "",
241+
"left": "",
242+
"top": "",
243+
"width": "",
244+
"height": ""
245+
},
246+
"allowCalculateOverride": false,
247+
"encrypted": false,
248+
"showCharCount": false,
249+
"showWordCount": false,
250+
"properties": {},
251+
"allowMultipleMasks": false,
252+
"addons": [],
253+
"serverOverride": {},
254+
"size": "md",
255+
"leftIcon": "",
256+
"rightIcon": "",
257+
"block": false,
258+
"action": "submit",
259+
"theme": "primary"
260+
}
261+
]
262+
}

src/process/__tests__/process.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import assert from 'node:assert';
3-
import type { ContainerComponent, ValidationScope } from 'types';
3+
import type { ContainerComponent, ProcessContext, ValidationScope } from 'types';
44
import { getComponent } from 'utils/formUtil';
55
import { process, processSync, Processors } from '../index';
66
import { fastCloneDeep } from 'utils';
@@ -16,6 +16,7 @@ import {
1616
skipValidWithHiddenParentComp,
1717
requiredFieldInsideEditGrid,
1818
formWithDefaultValues,
19+
requiredValidationDisabledByLogic,
1920
} from './fixtures';
2021
import _ from 'lodash';
2122

@@ -6027,6 +6028,26 @@ describe('Process Tests', function () {
60276028
expect((scope as ValidationScope).errors).to.have.length(1);
60286029
});
60296030

6031+
it('Should not trigger validation errors for components that remove required property by logic', async function () {
6032+
const form = requiredValidationDisabledByLogic;
6033+
const submission = {
6034+
data: {
6035+
b: '',
6036+
skipRequired: true,
6037+
},
6038+
};
6039+
const context = {
6040+
form,
6041+
submission: submission,
6042+
data: submission.data,
6043+
components: form.components,
6044+
processors: Processors,
6045+
scope: {} as ValidationScope,
6046+
} as ProcessContext<ValidationScope>;
6047+
processSync(context);
6048+
expect(context.scope.errors.length).to.equal(0);
6049+
});
6050+
60306051
describe('Required component validation in nested form in DataGrid/EditGrid', function () {
60316052
const nestedForm = {
60326053
key: 'form',

src/process/validation/rules/validateRequired.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ const valueIsPresent = (
8080

8181
export const shouldValidate = (context: ValidationContext): boolean => {
8282
const { component } = context;
83-
return !!component.scope?.required || !!component.validate?.required;
83+
if (component.scope?.hasOwnProperty('required')) {
84+
return !!component.scope?.required;
85+
}
86+
return !!component.validate?.required;
8487
};
8588

8689
export const validateRequired: RuleFn = async (context: ValidationContext) => {

0 commit comments

Comments
 (0)