Browse Source

Merge pull request #9857 from nocodb/nc-fix/form-validation-issue

fix(nc-gui): replace `[ ]` with `_`
pull/9822/head
Ramesh Mane 1 week ago committed by GitHub
parent
commit
ae586979b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      packages/nc-gui/utils/formValidations.ts

12
packages/nc-gui/utils/formValidations.ts

@ -141,8 +141,18 @@ export const extractFieldValidator = (_validators: Validation[], element: Column
return rules 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<string>) => { export const getValidFieldName = (title: string, uniqueFieldNames: Set<string>) => {
title = title.replace(/\./g, '_') title = title.replace(/\./g, '_').replace(/\[|\]/g, '_')
let counter = 1 let counter = 1
let newTitle = title let newTitle = title

Loading…
Cancel
Save