remoteoss / json-schema-form

https://json-schema-form.vercel.app
MIT License
85 stars 6 forks source link

fix(fieldset): Support customProperties with sub-fields clashing with reserved words. #64

Closed joeynimu closed 8 months ago

joeynimu commented 8 months ago

The bug(what) Passing the below jsfOption config to createHeadlessForm, we get an error;

createHeadlessForm(schema, {
  customProperties: {
    a_field_set: {
      name: { // 🔥 name is a reserved keyword
        type: "hidden", 
      },
    },
  },
});

The solution

This PR updates the path used for getting customizing (jsfOptions) of the fields inside a fieldset. Before this was been read from the parent field (fieldset) but now we read them within the customProperties of the parent field

// BEFORE
{
...
customProperties: get(config, `customProperties.${name}`, {})
}

//AFTER
{
...
customProperties: get(config, `customProperties.${name}.customProperties`, {})
}

And so the failing jsfOption example above becomes;

// 👍 works as expected
createHeadlessForm(schema, {
  customProperties: {
    a_field_set: {
      customProperties: {
        name: {
          type: "hidden",
        },
      },
    },
  },
});

It also updates test cases to read the customisation from the new path.

brennj commented 8 months ago

This is all good my side from testing it internally with Remote.