Closed sandrina-p closed 10 months ago
chore(fieldsets): ignores values not matching the field type
Given a JSON Schema that expects a fieldset...
{ properties: { a_fieldset: { title: 'Fieldset title', description: 'Fieldset description', 'x-jsf-presentation': { inputType: 'fieldset', }, properties: { id_number: mockTextInput, tabs: mockNumberInput, }, required: ['id_number'], type: 'object', }, }, required: ['a_fieldset'], }
And initialValues that do not match the fieldset structure (object)
initialValues
onst result = createHeadlessForm(schemaInputTypeFieldset, { initialValues: { a_fieldset: 'foo', // should be an object instead of string }, });
The json-schema-form fails with an error:
json-schema-form
TypeError: Cannot create property 'id_number' on string 'foo'
Check the fieldset's value type. If it's not an object, fallback to an empty object
fieldset
chore(fieldsets): ignores values not matching the field type
Steps to reproduce
Given a JSON Schema that expects a fieldset...
And
initialValues
that do not match the fieldset structure (object)The
json-schema-form
fails with an error:Solution
Check the
fieldset
's value type. If it's not an object, fallback to an empty object