tee3apps-cms-sdk-react 0.0.12 → 0.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tee3apps-cms-sdk-react",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Uses JSON to dynamically generate and render UI pages in a website",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -43,6 +43,15 @@ const PageForm: React.FC<PageFormProps> = ({ jsonData, onSubmit, isUrl = false,
43
43
  return component.props.name?.all || component.name;
44
44
  };
45
45
 
46
+ // Function to normalize field name: convert to lowercase and replace spaces/special characters with underscores
47
+ const normalizeFieldName = (name: string): string => {
48
+ return name
49
+ .toLowerCase()
50
+ .trim()
51
+ .replace(/[^a-z0-9]+/g, '_') // Replace any sequence of non-alphanumeric characters with single underscore
52
+ .replace(/^_+|_+$/g, ''); // Remove leading/trailing underscores
53
+ };
54
+
46
55
  // Function to create a mapping of field codes to field names
47
56
  const getFieldCodeToNameMap = useCallback(() => {
48
57
  const codeToNameMap: Record<string, string> = {};
@@ -93,10 +102,13 @@ const PageForm: React.FC<PageFormProps> = ({ jsonData, onSubmit, isUrl = false,
93
102
  Object.keys(formValues).forEach((code) => {
94
103
  const fieldName = codeToNameMap[code];
95
104
  if (fieldName) {
96
- transformedData[fieldName] = formValues[code];
105
+ // Normalize field name: convert to lowercase and replace spaces/special characters with underscores
106
+ const normalizedName = normalizeFieldName(fieldName);
107
+ transformedData[normalizedName] = formValues[code];
97
108
  } else {
98
- // If no mapping found, keep the code as key
99
- transformedData[code] = formValues[code];
109
+ // If no mapping found, normalize the code as well
110
+ const normalizedCode = normalizeFieldName(code);
111
+ transformedData[normalizedCode] = formValues[code];
100
112
  }
101
113
  });
102
114