diff --git a/src/@episerver/forms-sdk/src/form-loader/formLoader.ts b/src/@episerver/forms-sdk/src/form-loader/formLoader.ts index f65b371..df7674f 100644 --- a/src/@episerver/forms-sdk/src/form-loader/formLoader.ts +++ b/src/@episerver/forms-sdk/src/form-loader/formLoader.ts @@ -84,15 +84,12 @@ export class FormLoader { }), }) .then(async (response: Response) => { - if(response.ok){ + if (response.ok) { let json = await response.json(); - let formStr = json.data.FormContainerBlock.items[0]?.FormRenderTemplate; - if(formStr){ - resolve(JSON.parse(formStr) as T); - } - else { - reject(response); - } + let formStr = json.data.FormContainer.items[0]; + console.log(formStr) + let convertedFormStr = this.convertFirstLetterToLowerCase(formStr) as T + resolve(convertedFormStr) } else { reject(response); @@ -103,4 +100,22 @@ export class FormLoader { }); }); } + + /** + * Function to convert the first letter of object keys to lowercase + * @param data Data in json format + * **/ + private convertFirstLetterToLowerCase(data: any): any { + const isObject = typeof data === 'object' + if (data && isObject && !Array.isArray(data)) { + return Object.keys(data).reduce((accumulator, key) => { + const normalizedKey = key.charAt(0).toLowerCase() + key.slice(1); + accumulator[normalizedKey] = isObject ? this.convertFirstLetterToLowerCase(data[key]) : data[key]; + return accumulator; + }, {} as any); + } else if (Array.isArray(data)) { + return data.map(item => this.convertFirstLetterToLowerCase(item)); + } + return data; + } } \ No newline at end of file