Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data bug on nested property with numeric key #2397

Open
the-pegu opened this issue Nov 28, 2024 · 1 comment
Open

Update data bug on nested property with numeric key #2397

the-pegu opened this issue Nov 28, 2024 · 1 comment

Comments

@the-pegu
Copy link

Describe the bug

Updating data for nested property with numeric key is working kinda funny 😅
For that kind of schema:

{
  "type": "object",
  "properties": {
    "group-key": {
      "type": "object",
      "properties": {
        "15": {
          "type": "string"
        }
      }
    }
  },
}

updating data for property with "15" key will result in assigning to "group-key" an array of 16 elements where first 15 are null and at index 15 you will have value that you entered.
Something like that:

{
  "group-key": [
    null, null, null, null, null,
    null, null, null, null, null,
    null, null, null, null, null,
    "something"
  ]
}

Expected behavior

Expected data would be:

{
  "group-key": {
    "15": "something"
  }
}

Steps to reproduce the issue

  1. Create schema with nested numeric key:
{
  "type": "object",
  "properties": {
    "group-key": {
      "type": "object",
      "properties": {
        "15": {
          "type": "string"
        }
      }
    }
  },
}
  1. Create UiSchema:
{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Group",
      "label": "Some Group",
      "elements": [
        {
          "type": "Control",
          "label": "Label",
          "scope": "#/properties/group-key/properties/15"
        }
      ]
    }
  ]
}
  1. Enter some text in nested input
  2. See data of form:
{
  "group": [
    null, null, null, null, null,
    null, null, null, null, null,
    null, null, null, null, null,
    "something"
  ]
}

Screenshots

No response

Which Version of JSON Forms are you using?

v3.2.1

Package

React Material Renderers

Additional context

{
  "type": "object",
  "properties": {
    "group": {
      "type": "object",
      "properties": {
        "15": {
          "type": "string"
        },
        "non-numeric-key": {
          "type": "string"
        }
      }
    }
  },
  "required": []
}

if there are two nested field and firstly you will enter value for "non-numeric-key" then everything will work fine.
It will look like this:

{
  "group-key": {
    "non-numeric-key": "something"
  }
}

then numeric key will be added correctly:

{
  "group-key": {
    "15": "hello there",
    "non-numeric-key": "something"
  }
}

But the other way will result in array with null elements

@lucas-koehler
Copy link
Contributor

Thanks for the report! This is based on discussion: https://jsonforms.discourse.group/t/weird-bug-on-nested-property-with-numeric-key/2464
It can also be reproduced with 3.4.1

From the discussion:

As a guide for a potential fix: I’m pretty sure that is a consequence of lodash set which we are using to update the data, interpreting the “number-string” as an array index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants