Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modify-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface ModifyResult {
* shortToFullPath('foo.bar') // 'foo.properties.bar'
*/
function shortToFullPath(path: string) {
return path.replace('.', '.properties.')
return path.replaceAll('.', '.properties.')
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/fields/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
27 changes: 26 additions & 1 deletion test/modify-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ describe('modifySchema', () => {
city: {
title: 'City',
},
apartment: {
title: 'House',
properties: {
floor: {
title: 'Floor',
},
number: {
title: 'Number',
},
},
},
},
},
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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',
},
},
},
},
},
},
Expand Down