formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

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

Open tolbertncsa opened this issue 2 years ago • 4 comments

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

tolbertncsa avatar Aug 31 '23 19:08 tolbertncsa

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.

travist avatar Sep 28 '23 12:09 travist

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

Sidiro23 avatar May 15 '24 13:05 Sidiro23