Skip to content

Form with an object with enabled additionalProperties tries to insert data into a wrong fieldΒ #2423

@northpl93

Description

@northpl93

Describe the bug

Let's assume that we have a form with such a schema:

const schema = {
  properties: {
    someObject: {
      type: "object",
      additionalProperties: {
        type: "string"
      }
    }
  },
};

when I try to use the form and add a new field to the object, the field gets inserted, but it's constantly empty when I insert text into the form.

{
  "someObject": {
    "someKey": ""
  }
}

After some debugging, I discovered that jsonforms/vue-vuetify tries to insert data into someObject.someKey.someKey field instead of someObject.someKey

Expected behavior

The value I inserted into the form should appear in the data

{
  "someObject": {
    "someKey": "my text"
  }
}

Steps to reproduce the issue

  1. Clone https://github.com/eclipsesource/jsonforms-vue-seed
  2. Remove @jsonforms/vue-vanilla, install vuetify and @jsonforms/vue-vuetify
  3. Make necessary changes in main.ts to enable vuetify
  4. Change renderers in App.vue to extendedVuetifyRenderers
  5. Change schema in App.vue to something like this:
const schema = {
  properties: {
    someObject: {
      type: "object",
      additionalProperties: {
        type: "string"
      }
    }
  },
};

const uischema = {
  type: "VerticalLayout",
  elements: [
    {
      type: "Control",
      scope: "#/properties/someObject"
    }
  ],
};

const data = ref({
  someObject: {}
});
  1. Launch the application
  2. Insert the new key in the form, it should appear in the JSON data preview below the form
  3. Write some text in that value, it doesn't appear in the data preview

Screenshots

Image

Which Version of JSON Forms are you using?

3.5.1

Package

Vue Vuetify Renderers

Additional context

I put a breakpoint in the mapStateToControlProps function in renderer.ts file and I discovered that the key name is duplicated in the property that jsonforms tries to modify
Image

after some more digging, I think that the issue is in toAdditionalPropertyType function in AdditionalProperties.vue file

      return {
        propertyName: propName,
        path: composePaths(control.value.path, propName),
        schema: propSchema,
        uischema: propUiSchema,
      };

when I removed the call to composePaths function

      return {
        propertyName: propName,
        path: control.value.path,
        schema: propSchema,
        uischema: propUiSchema,
      };

it seems to work.
Image

But I don't know if such a fix breaks other things.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions