From 41e51fca3ab1cc05332d5552d344a07a357700b3 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:13:41 +0000 Subject: [PATCH 1/2] fix(nc-gui): replace `[ ]` with `_` --- packages/nc-gui/utils/formValidations.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/utils/formValidations.ts b/packages/nc-gui/utils/formValidations.ts index 6cc5ba64ab..1586eff03a 100644 --- a/packages/nc-gui/utils/formValidations.ts +++ b/packages/nc-gui/utils/formValidations.ts @@ -142,7 +142,8 @@ export const extractFieldValidator = (_validators: Validation[], element: Column } export const getValidFieldName = (title: string, uniqueFieldNames: Set) => { - title = title.replace(/\./g, '_') + // Replace invalid characters: '.' and '[]' with '_' + title = title.replace(/\./g, '_').replace(/\[|\]/g, '_') let counter = 1 let newTitle = title From 4aa347197d7a75a474dcbcf9867406191e897c68 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:13:42 +0000 Subject: [PATCH 2/2] fix(nc-gui): update description --- packages/nc-gui/utils/formValidations.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/utils/formValidations.ts b/packages/nc-gui/utils/formValidations.ts index 1586eff03a..4894d47f44 100644 --- a/packages/nc-gui/utils/formValidations.ts +++ b/packages/nc-gui/utils/formValidations.ts @@ -141,8 +141,17 @@ export const extractFieldValidator = (_validators: Validation[], element: Column return rules } +/** + * @description: + * This function sanitizes field names to ensure they are valid for form validation and avoid issues with nested object notation. + * - Replaces dots ('.') with underscores ('_') because dot notation is used to access object properties in many form validation libraries (e.g., useForm), + * and having dots can cause the field to be treated as a nested object rather than a simple property. + * - Replaces square brackets ('[]') with underscores ('_') to avoid the field being interpreted as an array or nested structure. + * + * This ensures the field names are flat, unique, and compatible with form validation libraries. + * If the sanitized name already exists, a counter is appended to make it unique. + */ export const getValidFieldName = (title: string, uniqueFieldNames: Set) => { - // Replace invalid characters: '.' and '[]' with '_' title = title.replace(/\./g, '_').replace(/\[|\]/g, '_') let counter = 1