Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/FIO-8389_editgr…
Browse files Browse the repository at this point in the history
…id_with_conditinal_logic
  • Loading branch information
lane-formio committed Jun 4, 2024
2 parents 4e24340 + d9af57a commit 417c2cc
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 56 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"./process": "./lib/process/index.js",
"./types": "./lib/types/index.js",
"./experimental": "./lib/experimental/index.js",
"./dist/formio.core.min.js": "./dist/formio.core.min.js"
"./dist/formio.core.min.js": "./dist/formio.core.min.js",
"./error": "./lib/error/index.js"
},
"scripts": {
"test": "TEST=1 mocha -r ts-node/register -r tsconfig-paths/register -r mock-local-storage -r jsdom-global/register -b -t 0 'src/**/__tests__/*.test.ts'",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './modules';
export * from './utils';
export * from './process/validation';
export * from './process/validation/rules';
export * from './process';
export * from './sdk';
export * from './types';
export * from './error';
4 changes: 4 additions & 0 deletions src/process/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ const normalizeTextFieldComponentValue = (
value: any,
path: string
) => {
// If the component has truncate multiple spaces enabled, then normalize the value to remove extra spaces.
if (component.truncateMultipleSpaces && typeof value === 'string') {
value = value.trim().replace(/\s{2,}/g, ' ');
}
if (component.allowMultipleMasks && component.inputMasks && component.inputMasks.length > 0) {
if (Array.isArray(value)) {
return value.map((val) => normalizeMaskValue(component, defaultValues, val, path));
Expand Down
3 changes: 0 additions & 3 deletions src/process/validation/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export const EN_ERRORS = {
invalidValueProperty: 'Invalid Value Property',
mask: '{{field}} does not match the mask.',
valueIsNotAvailable: '{{ field }} is an invalid value.',
captchaTokenValidation: 'ReCAPTCHA: Token validation error',
captchaTokenNotSpecified: 'ReCAPTCHA: Token is not specified in submission',
captchaFailure: 'ReCaptcha: Response token not found',
time: '{{field}} is not a valid time.',
invalidDate: '{{field}} is not a valid date',
number: '{{field}} is not a valid number.'
Expand Down
2 changes: 0 additions & 2 deletions src/process/validation/rules/databaseRules.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ValidationRuleInfo } from "types";
import { validateUniqueInfo } from "./validateUnique";
import { validateCaptchaInfo } from "./validateCaptcha";
import { validateResourceSelectValueInfo } from "./validateResourceSelectValue";

// These are the validations that require a database connection.
export const databaseRules: ValidationRuleInfo[] = [
validateUniqueInfo,
validateCaptchaInfo,
validateResourceSelectValueInfo
];
42 changes: 0 additions & 42 deletions src/process/validation/rules/validateCaptcha.ts

This file was deleted.

9 changes: 5 additions & 4 deletions src/process/validation/rules/validateRequired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DayComponent
} from 'types';
import { isEmptyObject } from '../util';
import { isComponentNestedDataType } from 'utils/formUtil';
import { ProcessorInfo } from 'types/process/ProcessorInfo';

const isAddressComponent = (component: any): component is AddressComponent => {
Expand All @@ -28,7 +29,7 @@ const isComponentThatCannotHaveFalseValue = (component: any): boolean => {
return component.type === 'checkbox' || component.type === 'selectboxes'
}

const valueIsPresent = (value: any, considerFalseTruthy: boolean): boolean => {
const valueIsPresent = (value: any, considerFalseTruthy: boolean, isNestedDatatype?: boolean): boolean => {
// Evaluate for 3 out of 6 falsy values ("", null, undefined), don't check for 0
// and only check for false under certain conditions
if (value === null || value === undefined || value === "" || (!considerFalseTruthy && value === false)) {
Expand All @@ -43,7 +44,7 @@ const valueIsPresent = (value: any, considerFalseTruthy: boolean): boolean => {
return false;
}
// Recursively evaluate
else if (typeof value === 'object') {
else if (typeof value === 'object' && !isNestedDatatype) {
return Object.values(value).some((val) => valueIsPresent(val, considerFalseTruthy));
}
return true;
Expand Down Expand Up @@ -74,9 +75,9 @@ export const validateRequiredSync: RuleFnSync = (context: ValidationContext) =>
return error;
}
else if (isComponentThatCannotHaveFalseValue(component)) {
return !valueIsPresent(value, false) ? error : null;
return !valueIsPresent(value, false, isComponentNestedDataType(component)) ? error : null;
}
return !valueIsPresent(value, true) ? error : null;
return !valueIsPresent(value, true, isComponentNestedDataType(component)) ? error : null;
};

export const validateRequiredInfo: ProcessorInfo<ValidationContext, FieldError | null> = {
Expand Down
5 changes: 3 additions & 2 deletions src/types/project/settings/ProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ProjectFileStorageConfig,
ProjectGoogleDriveConfig,
ProjectKickboxConfig,
ProjectReCaptchaConfig,
ProjectCaptchaConfig,
ProjectSQLConnectorConfig,
} from './integrations';

Expand Down Expand Up @@ -39,7 +39,8 @@ export type ProjectSettings = {

// Integrations
email?: ProjectEmailConfig;
recaptcha?: ProjectReCaptchaConfig;
captcha?: ProjectCaptchaConfig;
recaptcha?: ProjectCaptchaConfig;
esign?: ProjectESignConfig;
google?: ProjectGoogleDriveConfig;
kickbox?: ProjectKickboxConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ProjectReCaptchaConfig = {
export type ProjectCaptchaConfig = {
siteKey: string;
secretKey: string;
};
2 changes: 1 addition & 1 deletion src/types/project/settings/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './dataConnections';
export * from './email';
export * from './eSign';
export * from './fileStorage';
export * from './reCaptcha';
export * from './captcha';

0 comments on commit 417c2cc

Please sign in to comment.