nox-validation 1.7.8 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers.js +57 -57
- package/lib/validate.js +94 -88
- package/package.json +1 -1
- package/lib/helpers.optimized.js +0 -1975
- package/lib/validate.optimized.js +0 -1855
package/lib/validate.js
CHANGED
|
@@ -30,6 +30,14 @@ const relational_interfaces = [
|
|
|
30
30
|
constants.interfaces.TRANSLATIONS,
|
|
31
31
|
];
|
|
32
32
|
|
|
33
|
+
const arrayInterfaces = [
|
|
34
|
+
constants.interfaces.CHECKBOX,
|
|
35
|
+
constants.interfaces.ITEMS,
|
|
36
|
+
constants.interfaces.MULTIPLE_DROPDOWN,
|
|
37
|
+
constants.interfaces.TAGS,
|
|
38
|
+
constants.interfaces.ARRAY_OF_VALUES,
|
|
39
|
+
];
|
|
40
|
+
|
|
33
41
|
const typeChecks = {
|
|
34
42
|
date: (val, data) => {
|
|
35
43
|
if (val instanceof Date && !isNaN(val)) return true;
|
|
@@ -133,7 +141,7 @@ const handleMinMaxValidation = (
|
|
|
133
141
|
addError,
|
|
134
142
|
currentPath,
|
|
135
143
|
error_messages,
|
|
136
|
-
custom_message
|
|
144
|
+
custom_message,
|
|
137
145
|
) => {
|
|
138
146
|
let message = "";
|
|
139
147
|
const fieldLabel = formatLabel(field.display_label);
|
|
@@ -186,7 +194,7 @@ const handleMinMaxValidation = (
|
|
|
186
194
|
addError(
|
|
187
195
|
currentPath,
|
|
188
196
|
{ label: fieldLabel, fieldPath: currentPath, description: "", message },
|
|
189
|
-
field
|
|
197
|
+
field,
|
|
190
198
|
);
|
|
191
199
|
}
|
|
192
200
|
};
|
|
@@ -233,13 +241,13 @@ const isEmptyRelational = ({
|
|
|
233
241
|
? existingValue.length === 0
|
|
234
242
|
? []
|
|
235
243
|
: typeof existingValue[0] === "string"
|
|
236
|
-
|
|
237
|
-
|
|
244
|
+
? existingValue
|
|
245
|
+
: existingValue.map((item) => item._id)
|
|
238
246
|
: typeof existingValue === "string"
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
247
|
+
? [existingValue]
|
|
248
|
+
: existingValue && typeof existingValue === "object"
|
|
249
|
+
? [existingValue._id]
|
|
250
|
+
: [];
|
|
243
251
|
all = Array.isArray(all) ? all?.filter(Boolean) : all;
|
|
244
252
|
switch (interface) {
|
|
245
253
|
case constants.interfaces.FILE:
|
|
@@ -282,7 +290,7 @@ const validateMetaRules = (
|
|
|
282
290
|
language_codes = [],
|
|
283
291
|
existingForm = {},
|
|
284
292
|
getNodes = true,
|
|
285
|
-
translatedPath = null
|
|
293
|
+
translatedPath = null,
|
|
286
294
|
) => {
|
|
287
295
|
const fieldValue = providedValue;
|
|
288
296
|
|
|
@@ -311,11 +319,12 @@ const validateMetaRules = (
|
|
|
311
319
|
|
|
312
320
|
if (
|
|
313
321
|
choices.includes(field?.meta?.interface) &&
|
|
314
|
-
(!options?.choices || !options?.choices?.length > 0)
|
|
322
|
+
(!options?.choices || !options?.choices?.length > 0) &&
|
|
323
|
+
required
|
|
315
324
|
) {
|
|
316
325
|
const message = error_messages.ADD_CHOICE.replace(
|
|
317
326
|
`{field}`,
|
|
318
|
-
formatLabel(field.display_label)
|
|
327
|
+
formatLabel(field.display_label),
|
|
319
328
|
);
|
|
320
329
|
addError(
|
|
321
330
|
currentPath,
|
|
@@ -325,18 +334,10 @@ const validateMetaRules = (
|
|
|
325
334
|
description: "",
|
|
326
335
|
message,
|
|
327
336
|
},
|
|
328
|
-
field
|
|
337
|
+
field,
|
|
329
338
|
);
|
|
330
339
|
}
|
|
331
340
|
|
|
332
|
-
const arrayInterfaces = [
|
|
333
|
-
constants.interfaces.CHECKBOX,
|
|
334
|
-
constants.interfaces.ITEMS,
|
|
335
|
-
constants.interfaces.MULTIPLE_DROPDOWN,
|
|
336
|
-
constants.interfaces.TAGS,
|
|
337
|
-
constants.interfaces.ARRAY_OF_VALUES,
|
|
338
|
-
];
|
|
339
|
-
|
|
340
341
|
if (
|
|
341
342
|
required &&
|
|
342
343
|
arrayInterfaces.includes(field?.meta?.interface) &&
|
|
@@ -347,7 +348,7 @@ const validateMetaRules = (
|
|
|
347
348
|
) {
|
|
348
349
|
const message = error_messages.NOT_EMPTY.replace(
|
|
349
350
|
`{field}`,
|
|
350
|
-
formatLabel(field.display_label)
|
|
351
|
+
formatLabel(field.display_label),
|
|
351
352
|
);
|
|
352
353
|
addError(
|
|
353
354
|
currentPath,
|
|
@@ -357,7 +358,7 @@ const validateMetaRules = (
|
|
|
357
358
|
description: "",
|
|
358
359
|
message,
|
|
359
360
|
},
|
|
360
|
-
field
|
|
361
|
+
field,
|
|
361
362
|
);
|
|
362
363
|
}
|
|
363
364
|
|
|
@@ -376,7 +377,7 @@ const validateMetaRules = (
|
|
|
376
377
|
?.replace(".create", "")
|
|
377
378
|
?.replace(".update", "")
|
|
378
379
|
?.replace(".existing", "")
|
|
379
|
-
?.replace(".delete", "")
|
|
380
|
+
?.replace(".delete", ""),
|
|
380
381
|
), // TODO: Need to Generate Form Path Without create, update, existing, delete
|
|
381
382
|
})
|
|
382
383
|
: true;
|
|
@@ -398,11 +399,11 @@ const validateMetaRules = (
|
|
|
398
399
|
const message = field?.meta?.required
|
|
399
400
|
? error_messages.REQUIRED.replace(
|
|
400
401
|
`{field}`,
|
|
401
|
-
formatLabel(field.display_label)
|
|
402
|
+
formatLabel(field.display_label),
|
|
402
403
|
)
|
|
403
404
|
: error_messages.NOT_EMPTY.replace(
|
|
404
405
|
`{field}`,
|
|
405
|
-
formatLabel(field.display_label)
|
|
406
|
+
formatLabel(field.display_label),
|
|
406
407
|
);
|
|
407
408
|
|
|
408
409
|
addError(
|
|
@@ -421,14 +422,14 @@ const validateMetaRules = (
|
|
|
421
422
|
description: "",
|
|
422
423
|
message,
|
|
423
424
|
},
|
|
424
|
-
field
|
|
425
|
+
field,
|
|
425
426
|
);
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
if (!nullable && fieldValue === null) {
|
|
429
430
|
const message = error_messages.NOT_EMPTY.replace(
|
|
430
431
|
`{field}`,
|
|
431
|
-
formatLabel(field.display_label)
|
|
432
|
+
formatLabel(field.display_label),
|
|
432
433
|
);
|
|
433
434
|
addError(
|
|
434
435
|
currentPath,
|
|
@@ -438,7 +439,7 @@ const validateMetaRules = (
|
|
|
438
439
|
description: "",
|
|
439
440
|
message,
|
|
440
441
|
},
|
|
441
|
-
field
|
|
442
|
+
field,
|
|
442
443
|
);
|
|
443
444
|
}
|
|
444
445
|
|
|
@@ -594,7 +595,7 @@ const validateMetaRules = (
|
|
|
594
595
|
node?.value?.includes("create[0]")
|
|
595
596
|
) {
|
|
596
597
|
langPath = rebuildFullPath(node.value, fPath, (path) =>
|
|
597
|
-
path.replace(/create\[0\]\./, `create[${index}].`)
|
|
598
|
+
path.replace(/create\[0\]\./, `create[${index}].`),
|
|
598
599
|
);
|
|
599
600
|
transformedPath = rebuildFullPath(node.value, fPath, (path) => {
|
|
600
601
|
const newPath = path
|
|
@@ -608,7 +609,7 @@ const validateMetaRules = (
|
|
|
608
609
|
});
|
|
609
610
|
|
|
610
611
|
transformedPath = rebuildFullPath(node.value, fPath, (path) =>
|
|
611
|
-
path.replace(/\[0\]\./, `.${lang}.`)?.replace("create", "")
|
|
612
|
+
path.replace(/\[0\]\./, `.${lang}.`)?.replace("create", ""),
|
|
612
613
|
);
|
|
613
614
|
}
|
|
614
615
|
|
|
@@ -619,7 +620,7 @@ const validateMetaRules = (
|
|
|
619
620
|
} else {
|
|
620
621
|
const singlePath = fPath.replace(
|
|
621
622
|
"create.",
|
|
622
|
-
isTranslationNode ? "create[lang_code]." : "create[0]."
|
|
623
|
+
isTranslationNode ? "create[lang_code]." : "create[0].",
|
|
623
624
|
);
|
|
624
625
|
if (
|
|
625
626
|
constants.interfaces.ITEMS === field?.meta?.interface
|
|
@@ -635,14 +636,14 @@ const validateMetaRules = (
|
|
|
635
636
|
const validType =
|
|
636
637
|
field?.alternateType?.length > 0
|
|
637
638
|
? [field.type, ...field?.alternateType].some((type) =>
|
|
638
|
-
typeChecks[type](fieldValue)
|
|
639
|
+
typeChecks[type](fieldValue),
|
|
639
640
|
)
|
|
640
641
|
: typeChecks[field.type](fieldValue, { key: currentPath, updateValue });
|
|
641
642
|
|
|
642
643
|
if (!isEmpty(fieldValue) && !validType) {
|
|
643
644
|
const message = error_messages.INVALID_TYPE.replace(
|
|
644
645
|
`{field}`,
|
|
645
|
-
formatLabel(field.display_label)
|
|
646
|
+
formatLabel(field.display_label),
|
|
646
647
|
).replace(`{type}`, field?.type);
|
|
647
648
|
addError(
|
|
648
649
|
currentPath,
|
|
@@ -652,7 +653,7 @@ const validateMetaRules = (
|
|
|
652
653
|
description: "",
|
|
653
654
|
message,
|
|
654
655
|
},
|
|
655
|
-
field
|
|
656
|
+
field,
|
|
656
657
|
);
|
|
657
658
|
}
|
|
658
659
|
};
|
|
@@ -664,7 +665,7 @@ const handleRegexValidation = (
|
|
|
664
665
|
addError,
|
|
665
666
|
currentPath,
|
|
666
667
|
error_messages,
|
|
667
|
-
custom_message
|
|
668
|
+
custom_message,
|
|
668
669
|
) => {
|
|
669
670
|
function escapeRegex(str) {
|
|
670
671
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -751,7 +752,7 @@ const handleRegexValidation = (
|
|
|
751
752
|
addError(
|
|
752
753
|
currentPath,
|
|
753
754
|
{ label: fieldLabel, fieldPath: currentPath, description: "", message },
|
|
754
|
-
field
|
|
755
|
+
field,
|
|
755
756
|
);
|
|
756
757
|
}
|
|
757
758
|
};
|
|
@@ -765,7 +766,7 @@ const validateOperatorRule = (
|
|
|
765
766
|
formData,
|
|
766
767
|
error_messages,
|
|
767
768
|
custom_message,
|
|
768
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
769
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
769
770
|
) => {
|
|
770
771
|
const { isFieldCompare = false } = rule?.options ?? {};
|
|
771
772
|
let valid = false;
|
|
@@ -822,7 +823,7 @@ const validateOperatorRule = (
|
|
|
822
823
|
return Date.UTC(
|
|
823
824
|
date.getUTCFullYear(),
|
|
824
825
|
date.getUTCMonth(),
|
|
825
|
-
date.getUTCDate()
|
|
826
|
+
date.getUTCDate(),
|
|
826
827
|
);
|
|
827
828
|
};
|
|
828
829
|
|
|
@@ -840,7 +841,7 @@ const validateOperatorRule = (
|
|
|
840
841
|
// Format as YYYY-MM-DD
|
|
841
842
|
const date = new Date(value);
|
|
842
843
|
return `${date.getUTCFullYear()}-${String(
|
|
843
|
-
date.getUTCMonth() + 1
|
|
844
|
+
date.getUTCMonth() + 1,
|
|
844
845
|
).padStart(2, "0")}-${String(date.getUTCDate()).padStart(2, "0")}`;
|
|
845
846
|
}
|
|
846
847
|
// Return UTC midnight timestamp for comparison
|
|
@@ -1013,7 +1014,7 @@ const validateOperatorRule = (
|
|
|
1013
1014
|
description: "",
|
|
1014
1015
|
message,
|
|
1015
1016
|
},
|
|
1016
|
-
field
|
|
1017
|
+
field,
|
|
1017
1018
|
);
|
|
1018
1019
|
}
|
|
1019
1020
|
};
|
|
@@ -1023,7 +1024,7 @@ const generateErrorMessage = (
|
|
|
1023
1024
|
fieldLabel,
|
|
1024
1025
|
additionalValues = {},
|
|
1025
1026
|
error_messages,
|
|
1026
|
-
custom_message
|
|
1027
|
+
custom_message,
|
|
1027
1028
|
) => {
|
|
1028
1029
|
let message = custom_message ?? error_messages[ruleKey];
|
|
1029
1030
|
message = message?.replace(`{field}`, fieldLabel);
|
|
@@ -1041,7 +1042,7 @@ const handleRule = (
|
|
|
1041
1042
|
currentPath,
|
|
1042
1043
|
formData,
|
|
1043
1044
|
error_messages,
|
|
1044
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1045
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1045
1046
|
) => {
|
|
1046
1047
|
const ruleValue = rule?.value;
|
|
1047
1048
|
let messageValue = Array.isArray(ruleValue)
|
|
@@ -1059,7 +1060,7 @@ const handleRule = (
|
|
|
1059
1060
|
|
|
1060
1061
|
const labelValuePairs = ruleValues.map((val) => {
|
|
1061
1062
|
const matched = fieldChoices.find(
|
|
1062
|
-
(item) => String(item.value) === String(val)
|
|
1063
|
+
(item) => String(item.value) === String(val),
|
|
1063
1064
|
);
|
|
1064
1065
|
return matched ? `${matched.label} (${matched.value})` : val;
|
|
1065
1066
|
});
|
|
@@ -1079,10 +1080,10 @@ const handleRule = (
|
|
|
1079
1080
|
fieldLabel,
|
|
1080
1081
|
extraValues,
|
|
1081
1082
|
error_messages,
|
|
1082
|
-
custom_message
|
|
1083
|
+
custom_message,
|
|
1083
1084
|
),
|
|
1084
1085
|
},
|
|
1085
|
-
field
|
|
1086
|
+
field,
|
|
1086
1087
|
);
|
|
1087
1088
|
|
|
1088
1089
|
switch (rule.case) {
|
|
@@ -1102,7 +1103,7 @@ const handleRule = (
|
|
|
1102
1103
|
addValidationError(
|
|
1103
1104
|
"NOT_ONE_OF",
|
|
1104
1105
|
{ value: messageValue },
|
|
1105
|
-
custom_message
|
|
1106
|
+
custom_message,
|
|
1106
1107
|
);
|
|
1107
1108
|
break;
|
|
1108
1109
|
case constants.rulesTypes.NOT_ALLOWED:
|
|
@@ -1119,7 +1120,7 @@ const handleRule = (
|
|
|
1119
1120
|
addError,
|
|
1120
1121
|
currentPath,
|
|
1121
1122
|
error_messages,
|
|
1122
|
-
custom_message
|
|
1123
|
+
custom_message,
|
|
1123
1124
|
);
|
|
1124
1125
|
break;
|
|
1125
1126
|
case constants.rulesTypes.REGEX:
|
|
@@ -1130,7 +1131,7 @@ const handleRule = (
|
|
|
1130
1131
|
addError,
|
|
1131
1132
|
currentPath,
|
|
1132
1133
|
error_messages,
|
|
1133
|
-
custom_message
|
|
1134
|
+
custom_message,
|
|
1134
1135
|
);
|
|
1135
1136
|
break;
|
|
1136
1137
|
case constants.rulesTypes.OPERATOR:
|
|
@@ -1143,7 +1144,7 @@ const handleRule = (
|
|
|
1143
1144
|
formData,
|
|
1144
1145
|
error_messages,
|
|
1145
1146
|
custom_message,
|
|
1146
|
-
timeZone
|
|
1147
|
+
timeZone,
|
|
1147
1148
|
);
|
|
1148
1149
|
break;
|
|
1149
1150
|
default:
|
|
@@ -1166,7 +1167,7 @@ const validateField = (
|
|
|
1166
1167
|
existingForm,
|
|
1167
1168
|
getNodes = true,
|
|
1168
1169
|
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1169
|
-
translatedPath = null
|
|
1170
|
+
translatedPath = null,
|
|
1170
1171
|
) => {
|
|
1171
1172
|
const { is_m2a_item, staticType = null, parentInterface } = field?.meta;
|
|
1172
1173
|
const currentPath = fieldPath
|
|
@@ -1183,7 +1184,7 @@ const validateField = (
|
|
|
1183
1184
|
onlyFormFields == true &&
|
|
1184
1185
|
value === undefined &&
|
|
1185
1186
|
![constants.interfaces.TRANSLATIONS, constants.interfaces.SEO].includes(
|
|
1186
|
-
field?.meta?.interface
|
|
1187
|
+
field?.meta?.interface,
|
|
1187
1188
|
)
|
|
1188
1189
|
) {
|
|
1189
1190
|
if (
|
|
@@ -1197,7 +1198,7 @@ const validateField = (
|
|
|
1197
1198
|
const translationFieldPath = trimBasicPath(currentPath, staticType);
|
|
1198
1199
|
const existingItemValue = getValue(
|
|
1199
1200
|
existingForm,
|
|
1200
|
-
translationFieldPath
|
|
1201
|
+
translationFieldPath,
|
|
1201
1202
|
)?.find((item) => item.languages_code === langCode)?.[
|
|
1202
1203
|
`${field.key.split(".").pop()}`
|
|
1203
1204
|
];
|
|
@@ -1205,7 +1206,7 @@ const validateField = (
|
|
|
1205
1206
|
if (isEmpty(existingItemValue)) {
|
|
1206
1207
|
const message = error_messages.REQUIRED.replace(
|
|
1207
1208
|
`{field}`,
|
|
1208
|
-
formatLabel(`${field.key.split(".").pop()}`)
|
|
1209
|
+
formatLabel(`${field.key.split(".").pop()}`),
|
|
1209
1210
|
);
|
|
1210
1211
|
addError(
|
|
1211
1212
|
currentPath,
|
|
@@ -1216,10 +1217,10 @@ const validateField = (
|
|
|
1216
1217
|
description: "",
|
|
1217
1218
|
message,
|
|
1218
1219
|
},
|
|
1219
|
-
field
|
|
1220
|
+
field,
|
|
1220
1221
|
);
|
|
1221
1222
|
}
|
|
1222
|
-
} else return;
|
|
1223
|
+
} else if (field?.meta?.interface !== constants.interfaces.OBJECT) return;
|
|
1223
1224
|
}
|
|
1224
1225
|
|
|
1225
1226
|
const fieldLabel = formatLabel(field.display_label);
|
|
@@ -1238,14 +1239,15 @@ const validateField = (
|
|
|
1238
1239
|
language_codes,
|
|
1239
1240
|
existingForm,
|
|
1240
1241
|
getNodes,
|
|
1241
|
-
translatedPath
|
|
1242
|
+
translatedPath,
|
|
1242
1243
|
);
|
|
1243
1244
|
|
|
1244
1245
|
if (
|
|
1245
1246
|
field.type === constants.types.OBJECT &&
|
|
1246
|
-
field.children
|
|
1247
|
-
|
|
1248
|
-
|
|
1247
|
+
field.children
|
|
1248
|
+
// &&
|
|
1249
|
+
// !isEmpty(value) &&
|
|
1250
|
+
// typeChecks[constants.types.OBJECT](value)
|
|
1249
1251
|
) {
|
|
1250
1252
|
let itemSchemaId = null;
|
|
1251
1253
|
let childrenToValidate = field.children;
|
|
@@ -1257,7 +1259,7 @@ const validateField = (
|
|
|
1257
1259
|
childrenToValidate = [];
|
|
1258
1260
|
} else {
|
|
1259
1261
|
childrenToValidate = field.children.filter(
|
|
1260
|
-
(child) => child.schema_id === itemSchemaId
|
|
1262
|
+
(child) => child.schema_id === itemSchemaId,
|
|
1261
1263
|
);
|
|
1262
1264
|
}
|
|
1263
1265
|
}
|
|
@@ -1265,7 +1267,7 @@ const validateField = (
|
|
|
1265
1267
|
childrenToValidate.forEach((child) =>
|
|
1266
1268
|
validateField(
|
|
1267
1269
|
child,
|
|
1268
|
-
value[child.key.split(".").pop()],
|
|
1270
|
+
!isEmpty(value) ? value[child.key.split(".").pop()] : null,
|
|
1269
1271
|
currentPath,
|
|
1270
1272
|
addError,
|
|
1271
1273
|
formData,
|
|
@@ -1278,8 +1280,8 @@ const validateField = (
|
|
|
1278
1280
|
existingForm,
|
|
1279
1281
|
false,
|
|
1280
1282
|
timeZone,
|
|
1281
|
-
null
|
|
1282
|
-
)
|
|
1283
|
+
null,
|
|
1284
|
+
),
|
|
1283
1285
|
);
|
|
1284
1286
|
} else if (field.type === constants.types.ARRAY && Array.isArray(value)) {
|
|
1285
1287
|
const itemType = field?.array_type || field?.schema_definition?.type;
|
|
@@ -1301,7 +1303,7 @@ const validateField = (
|
|
|
1301
1303
|
itemPath,
|
|
1302
1304
|
formData,
|
|
1303
1305
|
error_messages,
|
|
1304
|
-
timeZone
|
|
1306
|
+
timeZone,
|
|
1305
1307
|
);
|
|
1306
1308
|
}
|
|
1307
1309
|
|
|
@@ -1316,7 +1318,7 @@ const validateField = (
|
|
|
1316
1318
|
{
|
|
1317
1319
|
type: itemType,
|
|
1318
1320
|
},
|
|
1319
|
-
error_messages
|
|
1321
|
+
error_messages,
|
|
1320
1322
|
),
|
|
1321
1323
|
});
|
|
1322
1324
|
}
|
|
@@ -1360,7 +1362,7 @@ const validateField = (
|
|
|
1360
1362
|
existingForm,
|
|
1361
1363
|
false,
|
|
1362
1364
|
timeZone,
|
|
1363
|
-
trPath
|
|
1365
|
+
trPath,
|
|
1364
1366
|
);
|
|
1365
1367
|
});
|
|
1366
1368
|
});
|
|
@@ -1374,7 +1376,7 @@ const validateField = (
|
|
|
1374
1376
|
currentPath,
|
|
1375
1377
|
formData,
|
|
1376
1378
|
error_messages,
|
|
1377
|
-
timeZone
|
|
1379
|
+
timeZone,
|
|
1378
1380
|
)
|
|
1379
1381
|
) {
|
|
1380
1382
|
addError(
|
|
@@ -1385,7 +1387,7 @@ const validateField = (
|
|
|
1385
1387
|
description: "",
|
|
1386
1388
|
message: error_messages.INVALID_VALUE?.replace(`{field}`, fieldLabel),
|
|
1387
1389
|
},
|
|
1388
|
-
field
|
|
1390
|
+
field,
|
|
1389
1391
|
);
|
|
1390
1392
|
}
|
|
1391
1393
|
}
|
|
@@ -1398,8 +1400,12 @@ const applyValidations = (
|
|
|
1398
1400
|
currentPath,
|
|
1399
1401
|
formData,
|
|
1400
1402
|
error_messages,
|
|
1401
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1403
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1402
1404
|
) => {
|
|
1405
|
+
if (arrayInterfaces.includes(field.meta?.interface)) {
|
|
1406
|
+
currentPath = currentPath.replace(/\[\d+\]$/, "");
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1403
1409
|
if (
|
|
1404
1410
|
!field.validations ||
|
|
1405
1411
|
isEmpty(value)
|
|
@@ -1418,8 +1424,8 @@ const applyValidations = (
|
|
|
1418
1424
|
currentPath,
|
|
1419
1425
|
formData,
|
|
1420
1426
|
error_messages,
|
|
1421
|
-
timeZone
|
|
1422
|
-
) === false
|
|
1427
|
+
timeZone,
|
|
1428
|
+
) === false,
|
|
1423
1429
|
);
|
|
1424
1430
|
};
|
|
1425
1431
|
|
|
@@ -1526,13 +1532,13 @@ const validate = (data) => {
|
|
|
1526
1532
|
typeChecks[constants.types.OBJECT](firstParentValue)
|
|
1527
1533
|
) {
|
|
1528
1534
|
const codeKey = Object.keys(firstParentValue).find((key) =>
|
|
1529
|
-
key.includes(languageKey)
|
|
1535
|
+
key.includes(languageKey),
|
|
1530
1536
|
);
|
|
1531
1537
|
const codeValue = codeKey ? firstParentValue[codeKey] : null;
|
|
1532
1538
|
if (codeValue) {
|
|
1533
1539
|
const translation_key = fieldPath.replace(
|
|
1534
1540
|
firstParent,
|
|
1535
|
-
`${secondParent}.${codeValue}
|
|
1541
|
+
`${secondParent}.${codeValue}`,
|
|
1536
1542
|
);
|
|
1537
1543
|
if (translation_key) {
|
|
1538
1544
|
obj.translation_path = translation_key;
|
|
@@ -1555,7 +1561,7 @@ const validate = (data) => {
|
|
|
1555
1561
|
if (!data) {
|
|
1556
1562
|
const message = error_messages.REQUIRED.replace(
|
|
1557
1563
|
`{field}`,
|
|
1558
|
-
formatLabel("data")
|
|
1564
|
+
formatLabel("data"),
|
|
1559
1565
|
);
|
|
1560
1566
|
addError(
|
|
1561
1567
|
"data",
|
|
@@ -1565,7 +1571,7 @@ const validate = (data) => {
|
|
|
1565
1571
|
description: "",
|
|
1566
1572
|
message,
|
|
1567
1573
|
},
|
|
1568
|
-
defaultField
|
|
1574
|
+
defaultField,
|
|
1569
1575
|
);
|
|
1570
1576
|
return result;
|
|
1571
1577
|
}
|
|
@@ -1574,7 +1580,7 @@ const validate = (data) => {
|
|
|
1574
1580
|
if (!typeChecks[constants.types.OBJECT](data)) {
|
|
1575
1581
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1576
1582
|
`{field}`,
|
|
1577
|
-
formatLabel("data")
|
|
1583
|
+
formatLabel("data"),
|
|
1578
1584
|
).replace(`{type}`, constants.types.OBJECT);
|
|
1579
1585
|
addError(
|
|
1580
1586
|
"data",
|
|
@@ -1584,7 +1590,7 @@ const validate = (data) => {
|
|
|
1584
1590
|
description: "",
|
|
1585
1591
|
message,
|
|
1586
1592
|
},
|
|
1587
|
-
defaultField
|
|
1593
|
+
defaultField,
|
|
1588
1594
|
);
|
|
1589
1595
|
return result;
|
|
1590
1596
|
}
|
|
@@ -1597,7 +1603,7 @@ const validate = (data) => {
|
|
|
1597
1603
|
if (fieldValue == null || fieldValue == undefined) {
|
|
1598
1604
|
const message = error_messages.REQUIRED.replace(
|
|
1599
1605
|
`{field}`,
|
|
1600
|
-
formatLabel(key)
|
|
1606
|
+
formatLabel(key),
|
|
1601
1607
|
);
|
|
1602
1608
|
addError(
|
|
1603
1609
|
key,
|
|
@@ -1607,7 +1613,7 @@ const validate = (data) => {
|
|
|
1607
1613
|
description: "",
|
|
1608
1614
|
message,
|
|
1609
1615
|
},
|
|
1610
|
-
defaultField
|
|
1616
|
+
defaultField,
|
|
1611
1617
|
);
|
|
1612
1618
|
return;
|
|
1613
1619
|
}
|
|
@@ -1616,7 +1622,7 @@ const validate = (data) => {
|
|
|
1616
1622
|
if (!typeChecks[expectedType] || !typeChecks[expectedType](fieldValue)) {
|
|
1617
1623
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1618
1624
|
`{field}`,
|
|
1619
|
-
key
|
|
1625
|
+
key,
|
|
1620
1626
|
).replace(`{type}`, expectedType);
|
|
1621
1627
|
addError(
|
|
1622
1628
|
key,
|
|
@@ -1626,7 +1632,7 @@ const validate = (data) => {
|
|
|
1626
1632
|
description: "",
|
|
1627
1633
|
message,
|
|
1628
1634
|
},
|
|
1629
|
-
defaultField
|
|
1635
|
+
defaultField,
|
|
1630
1636
|
);
|
|
1631
1637
|
return;
|
|
1632
1638
|
}
|
|
@@ -1644,7 +1650,7 @@ const validate = (data) => {
|
|
|
1644
1650
|
) {
|
|
1645
1651
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1646
1652
|
`{field}`,
|
|
1647
|
-
`${key}[${index}]
|
|
1653
|
+
`${key}[${index}]`,
|
|
1648
1654
|
).replace(`{type}`, arrayItemType);
|
|
1649
1655
|
addError(
|
|
1650
1656
|
`${key}[${index}]`,
|
|
@@ -1654,7 +1660,7 @@ const validate = (data) => {
|
|
|
1654
1660
|
description: "",
|
|
1655
1661
|
message,
|
|
1656
1662
|
},
|
|
1657
|
-
defaultField
|
|
1663
|
+
defaultField,
|
|
1658
1664
|
);
|
|
1659
1665
|
}
|
|
1660
1666
|
});
|
|
@@ -1665,7 +1671,7 @@ const validate = (data) => {
|
|
|
1665
1671
|
if (!constants.API_VERSIONS.includes(apiVersion)) {
|
|
1666
1672
|
const message = error_messages.IN.replace(
|
|
1667
1673
|
`{field}`,
|
|
1668
|
-
formatLabel("apiVersion")
|
|
1674
|
+
formatLabel("apiVersion"),
|
|
1669
1675
|
).replace(`{value}`, constants.API_VERSIONS.join(", "));
|
|
1670
1676
|
addError(
|
|
1671
1677
|
"apiVersion",
|
|
@@ -1675,7 +1681,7 @@ const validate = (data) => {
|
|
|
1675
1681
|
description: "",
|
|
1676
1682
|
message,
|
|
1677
1683
|
},
|
|
1678
|
-
defaultField
|
|
1684
|
+
defaultField,
|
|
1679
1685
|
);
|
|
1680
1686
|
}
|
|
1681
1687
|
|
|
@@ -1693,7 +1699,7 @@ const validate = (data) => {
|
|
|
1693
1699
|
|
|
1694
1700
|
if (!isSeparatedFields) {
|
|
1695
1701
|
schemaFields = fields.filter(
|
|
1696
|
-
(field) => field?.schema_id?.toString() === formId?.toString()
|
|
1702
|
+
(field) => field?.schema_id?.toString() === formId?.toString(),
|
|
1697
1703
|
);
|
|
1698
1704
|
}
|
|
1699
1705
|
|
|
@@ -1728,7 +1734,7 @@ const validate = (data) => {
|
|
|
1728
1734
|
{
|
|
1729
1735
|
field: formatLabel(fieldKey),
|
|
1730
1736
|
},
|
|
1731
|
-
error_messages
|
|
1737
|
+
error_messages,
|
|
1732
1738
|
),
|
|
1733
1739
|
});
|
|
1734
1740
|
}
|
|
@@ -1751,7 +1757,7 @@ const validate = (data) => {
|
|
|
1751
1757
|
existingForm,
|
|
1752
1758
|
true,
|
|
1753
1759
|
timeZone,
|
|
1754
|
-
null
|
|
1760
|
+
null,
|
|
1755
1761
|
);
|
|
1756
1762
|
});
|
|
1757
1763
|
return result;
|