diff --git a/src/modify-schema.ts b/src/modify-schema.ts index abfd6f94..f4794348 100644 --- a/src/modify-schema.ts +++ b/src/modify-schema.ts @@ -51,7 +51,7 @@ interface ModifyResult { * shortToFullPath('foo.bar') // 'foo.properties.bar' */ function shortToFullPath(path: string) { - return path.replace('.', '.properties.') + return path.replaceAll('.', '.properties.') } /** diff --git a/src/mutations.ts b/src/mutations.ts index f06e13fc..e7569411 100644 --- a/src/mutations.ts +++ b/src/mutations.ts @@ -181,10 +181,11 @@ export function updateFieldProperties(fields: Field[], schema: JsfObjectSchema, deepMergeSchemas(field, newField) const fieldSchema = schema.properties?.[field.name] + const originalFieldSchema = originalSchema.properties?.[field.name] if (fieldSchema && typeof fieldSchema === 'object') { if (field.fields && fieldSchema.type === 'object') { - updateFieldProperties(field.fields, fieldSchema as JsfObjectSchema, originalSchema) + updateFieldProperties(field.fields, fieldSchema as JsfObjectSchema, originalFieldSchema as JsfObjectSchema) } } } diff --git a/test/fields/mutation.test.ts b/test/fields/mutation.test.ts index 156e7c47..687a1481 100644 --- a/test/fields/mutation.test.ts +++ b/test/fields/mutation.test.ts @@ -439,6 +439,32 @@ describe('field mutation', () => { hint: 'Optional contact method', }) }) + + it('should be able to preserve x-jsf-presentation properties in a nested field', () => { + const customComponent = () => { + return null + } + const schema: JsfObjectSchema = { + type: 'object', + properties: { + apartment: { + type: 'object', + properties: { + number: { + 'type': 'string', + 'x-jsf-presentation': { + Component: customComponent, + }, + }, + }, + }, + }, + } + const form = createHeadlessForm(schema) + form.handleValidation({ formType: 'advanced' }) + + expect(getField(form.fields, 'apartment', 'number')).toHaveProperty('Component', customComponent) + }) }) it('correctly updates required on fields', () => { diff --git a/test/modify-schema.test.ts b/test/modify-schema.test.ts index 7d1031fe..31eccd11 100644 --- a/test/modify-schema.test.ts +++ b/test/modify-schema.test.ts @@ -107,6 +107,17 @@ describe('modifySchema', () => { city: { title: 'City', }, + apartment: { + title: 'House', + properties: { + floor: { + title: 'Floor', + }, + number: { + title: 'Number', + }, + }, + }, }, }, }, @@ -237,6 +248,10 @@ describe('modifySchema', () => { 'address.city': () => ({ title: 'City name', }), + // should be able to handle deep nested fields + 'address.apartment.number': { + title: 'Apartment Number', + }, // Or pass the native object 'address': (fieldAttrs) => { return { @@ -262,11 +277,21 @@ describe('modifySchema', () => { }, number: { 'title': 'Door Number', - 'x-test-siblings': ['street', 'number', 'city'], + 'x-test-siblings': ['street', 'number', 'city', 'apartment'], }, city: { title: 'City name', }, + apartment: { + properties: { + floor: { + title: 'Floor', + }, + number: { + title: 'Apartment Number', + }, + }, + }, }, }, },