Skip to content

Commit

Permalink
fix(fieldset): Support customProperties with sub-fields clashing with…
Browse files Browse the repository at this point in the history
… reserved words. (#64)

fix(fieldset): Support customProperties with sub-fields clashing with reserved words.
  • Loading branch information
joeynimu committed Feb 1, 2024
1 parent aa008c2 commit 8340cde
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/createHeadlessForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function buildFieldParameters(name, fieldProperties, required = [], config = {},
fields = getFieldsFromJSONSchema(
fieldProperties,
{
customProperties: get(config, `customProperties.${name}`, {}),
customProperties: get(config, `customProperties.${name}.customProperties`, {}),
parentID: name,
},
logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,18 @@ describe('createHeadlessForm() - custom validations', () => {
maximum: 28,
},
second_gen: {
cub_age: {
minimum: 18,
maximum: 21,
},
third_gen: {
grandcub_age: {
minimum: 10,
maximum: 15,
customProperties: {
cub_age: {
minimum: 18,
maximum: 21,
},
third_gen: {
customProperties: {
grandcub_age: {
minimum: 10,
maximum: 15,
},
},
},
},
},
Expand Down
64 changes: 61 additions & 3 deletions src/tests/createHeadlessForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3677,11 +3677,17 @@ describe('createHeadlessForm', () => {
customProperties: {
id_number: { 'data-field': 'field' },
fieldset: {
id_number: { 'data-fieldset': 'fieldset' },
customProperties: {
id_number: { 'data-fieldset': 'fieldset' },
},
},
nestedFieldset: {
innerFieldset: {
id_number: { 'data-nested-fieldset': 'nested-fieldset' },
customProperties: {
innerFieldset: {
customProperties: {
id_number: { 'data-nested-fieldset': 'nested-fieldset' },
},
},
},
},
},
Expand Down Expand Up @@ -3754,6 +3760,58 @@ describe('createHeadlessForm', () => {
expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-field');
expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-fieldset');
});
it('should handle custom properties when inside fieldsets for fields name clashing with reserved words', () => {
const { fields } = createHeadlessForm(
{
properties: {
dog: {
title: 'Dog details',
description: 'Fieldset description',
'x-jsf-presentation': {
inputType: 'fieldset',
},
properties: {
name: {
// This fieldName (name) clashs with the field specs "name"
title: 'Dogs name',
'x-jsf-presentation': {
inputType: 'text',
},
type: 'string',
},
type: {
// This field name (type) clashs with the field specs "type"
title: 'Breed type',
'x-jsf-presentation': {
inputType: 'number',
},
type: 'string',
},
},
required: ['name'],
type: 'object',
},
},
required: ['dog'],
},
{
customProperties: {
dog: {
customProperties: {
name: {
description: "What's your dogs name",
},
},
},
},
}
);

expect(fields.length).toBe(1);
expect(fields[0].fields.length).toBe(2);
expect(fields[0].fields[0].name).toBe('name');
expect(fields[0].fields[0].description).toBe("What's your dogs name");
});
});

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

0 comments on commit 8340cde

Please sign in to comment.