Skip to content

Commit 8340cde

Browse files
authored
fix(fieldset): Support customProperties with sub-fields clashing with reserved words. (#64)
fix(fieldset): Support customProperties with sub-fields clashing with reserved words.
1 parent aa008c2 commit 8340cde

File tree

3 files changed

+74
-12
lines changed

3 files changed

+74
-12
lines changed

src/createHeadlessForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function buildFieldParameters(name, fieldProperties, required = [], config = {},
111111
fields = getFieldsFromJSONSchema(
112112
fieldProperties,
113113
{
114-
customProperties: get(config, `customProperties.${name}`, {}),
114+
customProperties: get(config, `customProperties.${name}.customProperties`, {}),
115115
parentID: name,
116116
},
117117
logic

src/tests/createHeadlessForm.customValidations.test.jsx renamed to src/tests/createHeadlessForm.customValidations.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,18 @@ describe('createHeadlessForm() - custom validations', () => {
358358
maximum: 28,
359359
},
360360
second_gen: {
361-
cub_age: {
362-
minimum: 18,
363-
maximum: 21,
364-
},
365-
third_gen: {
366-
grandcub_age: {
367-
minimum: 10,
368-
maximum: 15,
361+
customProperties: {
362+
cub_age: {
363+
minimum: 18,
364+
maximum: 21,
365+
},
366+
third_gen: {
367+
customProperties: {
368+
grandcub_age: {
369+
minimum: 10,
370+
maximum: 15,
371+
},
372+
},
369373
},
370374
},
371375
},

src/tests/createHeadlessForm.test.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,11 +3677,17 @@ describe('createHeadlessForm', () => {
36773677
customProperties: {
36783678
id_number: { 'data-field': 'field' },
36793679
fieldset: {
3680-
id_number: { 'data-fieldset': 'fieldset' },
3680+
customProperties: {
3681+
id_number: { 'data-fieldset': 'fieldset' },
3682+
},
36813683
},
36823684
nestedFieldset: {
3683-
innerFieldset: {
3684-
id_number: { 'data-nested-fieldset': 'nested-fieldset' },
3685+
customProperties: {
3686+
innerFieldset: {
3687+
customProperties: {
3688+
id_number: { 'data-nested-fieldset': 'nested-fieldset' },
3689+
},
3690+
},
36853691
},
36863692
},
36873693
},
@@ -3754,6 +3760,58 @@ describe('createHeadlessForm', () => {
37543760
expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-field');
37553761
expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-fieldset');
37563762
});
3763+
it('should handle custom properties when inside fieldsets for fields name clashing with reserved words', () => {
3764+
const { fields } = createHeadlessForm(
3765+
{
3766+
properties: {
3767+
dog: {
3768+
title: 'Dog details',
3769+
description: 'Fieldset description',
3770+
'x-jsf-presentation': {
3771+
inputType: 'fieldset',
3772+
},
3773+
properties: {
3774+
name: {
3775+
// This fieldName (name) clashs with the field specs "name"
3776+
title: 'Dogs name',
3777+
'x-jsf-presentation': {
3778+
inputType: 'text',
3779+
},
3780+
type: 'string',
3781+
},
3782+
type: {
3783+
// This field name (type) clashs with the field specs "type"
3784+
title: 'Breed type',
3785+
'x-jsf-presentation': {
3786+
inputType: 'number',
3787+
},
3788+
type: 'string',
3789+
},
3790+
},
3791+
required: ['name'],
3792+
type: 'object',
3793+
},
3794+
},
3795+
required: ['dog'],
3796+
},
3797+
{
3798+
customProperties: {
3799+
dog: {
3800+
customProperties: {
3801+
name: {
3802+
description: "What's your dogs name",
3803+
},
3804+
},
3805+
},
3806+
},
3807+
}
3808+
);
3809+
3810+
expect(fields.length).toBe(1);
3811+
expect(fields[0].fields.length).toBe(2);
3812+
expect(fields[0].fields[0].name).toBe('name');
3813+
expect(fields[0].fields[0].description).toBe("What's your dogs name");
3814+
});
37573815
});
37583816

37593817
describe('presentation (deprecated in favor of x-jsf-presentation)', () => {

0 commit comments

Comments
 (0)