formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.87k stars 1.06k forks source link

[BUG] Datagrid in editForm has undefined row #5039

Open tkalmar opened 1 year ago

tkalmar commented 1 year ago

Environment

Please provide as many details as you can:

I have a textfield with the following additional properties:

properties: {
  foo: [{ bar: "Barvalue", baz: true },{ bar: "Barvalue2", baz: false }]

added the following form to the editForm of textfield:

{
  "weight": -1,
  "label": "Data Grid",
  "hideLabel": true,
  "disableAddingRemovingRows": true,
  "reorder": false,
  "addAnotherPosition": "bottom",
  "layoutFixed": false,
  "enableRowGroups": false,
  "initEmpty": false,
  "tableView": false,
  "defaultValue": [],
  "calculateValue": "value = instance.data.properties.foo",
  "customConditional": "show = instance.data.properties && instance.data.properties.foo && instance.data.properties.foo.length;",
  "key": "datagrid",
  "type": "datagrid",
  "input": true,
  "components": [
    {
      "title": "Foo",
      "collapsible": true,
      "key": "foo",
      "type": "panel",
      "input": false,
      "tableView": false,
      "customConditional": "if (row) { component.title='Foo ' + (row.bar) || ''); component.customClass= row.baz ? 'ruleBazOn':'ruleBazOff';}\nshow = true;",
      "components": [
        {
          "label": "Bar",
          "tableView": true,
          "key": "bar",
          "type": "textfield",
          "disabled": true
        },
        {
          "label": "Baz",
          "tooltip": "Is there Baz?",
          "tableView": false,
          "key": "baz",
          "type": "checkbox",
          "input": true
        }
      ],
      "collapsed": true
    }
  ]
}

added to the textfield editform as

{
        key: 'conditional',
        components: [fooForm],
      },

When i open the edit form of the textfield the first row is undefined (until i expand the Foo form) then suddenly the title of the panel changes from Foo undefined to Foo Barvalue

The second (and subsequent) panel is rendered correctly

Steps to Reproduce

  1. create a textfield with the given props
  2. add the form to the textfield Editform
  3. open the edit Form

Expected behavior

All Foo Panel are rendered correctly on opening

Observed behavior

The first Foo panel has no Data until opened

Example

Screenshot image

tkalmar commented 1 year ago

If i change the initEmpty to true in the datagrid everything works

daneformio commented 5 months ago

@tkalmar Is your issue resolved with that property change on the data grid?

tkalmar commented 5 months ago

Is it supposed to only work this way? Then yes.