formio / formio.js

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

Select field in datagrid displays "[object Object]" when rendering read-only #5332

Open tolbertncsa opened 1 year ago

tolbertncsa commented 1 year ago

Create a datagrid with a child component of type "select" and widget "choicesjs". Rendering this form in editable mode will work correctly. Rendering this form in read-only mode will display "[object Object]" instead of using the template value to format the object.

Expected behavior: the read-only view would display the templated label instead of [object], as the Select widget does when NOT in a datagrid.

My form definition for this component:

   {
      "label": "New Funding",
      "reorder": false,
      "addAnotherPosition": "bottom",
      "layoutFixed": false,
      "enableRowGroups": false,
      "initEmpty": false,
      "tableView": false,
      "key": "newFunding",
      "type": "datagrid",
      "input": true,
      "components": [
        {
          "label": "CFOPA",
          "widget": "choicesjs",
          "placeholder": "Select CFOPA",
          "tableView": true,
          "dataSrc": "url",
          "data": {
            "url": "/autocomplete/cfopa",
            "headers": [
              {
                "key": "",
                "value": ""
              }
            ]
          },
          "idPath": "cfopa_id",
          "template": "<span>{{ item.chart }}-{{ item.fund }}-{{ item.org }}--{{item.program}}--{{item.activity}} {{item.activity_name}}</span>",
          "validate": {
            "select": false
          },
          "key": "cfopa",
          "type": "select",
          "selectValues": "result",
          "disableLimit": false,
          "searchField": "search",
          "input": true
        },
        {
          "label": "Percent",
          "description": "Percent FTE",
          "key": "percent",
          "type": "textfield",
          "input": true,
          "tableView": true

        }
      ]
    },

readOnlyMode

editableMode

travist commented 1 year ago

Yes I agree this is a bug. It must have something to do with the "renderValueAsString" method call for the Select component. Is this something that maybe you are able to debug and propose a change? If so, we will happily review it and include your fix for the 5.x version we are working on. If not, then it will probably go into our internal Form.io developer queue, which is pretty long at the moment.

Sidiro23 commented 5 months ago

We have created a ticket for this and will review it with the team. Ticket for internal tracking: FIO-8362