formio / formio.js

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

Select Component with a "big list of options" with pagination API does not resolve attributes name (label name) displayed. Label Name resolution is not proper. #5435

Open nishit4777 opened 11 months ago

nishit4777 commented 11 months ago

Environment:

Steps to Reproduce

  1. Add a select component.
  2. In data tab choose Data Source Type as URL
  3. choose the API with pagination which gives data and configure the Data Path and Value Property accordingly.
  4. As in this example I am using a public API with the pre-data and pagination limit present. The label attribute is not here so the label name would be displayed as undefined here other wise it would display the label name if the attribute is present.
  5. The issue what is happening is in default value if you have some data selected which is not part of initial list in the paginated API the label name would not come up. Instead its value is showing.
  6. The same behavior is happening when you have two tabs and select data which is not part of initial list in the paginated API from the tab1 in select component and switch to other tab and come up, switching back to an old tab, name resolution is not proper. Instead of label the value is getting displayed which seems to be very ugly.

Expected behavior

Name Resolution should be proper if the Select Component with a "big list of options" with pagination API is used. Also switching back to tabs the selected value should retain the label name even though if it is not part of initial list.

Observed behavior

The issue what is happening is in default value if you have some data selected which is not part of initial list in the paginated API the label name would not come up. Instead its value is showing.

The same behavior is happening when you have two tabs and select data which is not part of initial list in the paginated API from the tab1 in select component and switch to other tab and come up, switching back to an old tab, name resolution is not proper. Instead of label the value is getting displayed which seems to be very ugly.

Note:

The values here is coming undefined only because the API response doesn't have label attribute. And the value is coming for some field which is not showing the label as it is not part of initial list. The values part of initial list comes as undefined here.

Attaching GIF

Defec-formio-select-NameResolution

Form Json


"display": "form",
    "settings": {
        "pdf": {
            "id": "1ec0f8ee-6685-5d98-a847-26f67b67d6f0",
            "src": "https://files.form.io/pdf/5692b91fd1028f01000407e3/file/1ec0f8ee-6685-5d98-a847-26f67b67d6f0"
        }
    },
    "components": [
        {
            "label": "Select",
            "widget": "choicesjs",
            "tableView": true,
            "multiple": true,
            "dataSrc": "url",
            "defaultValue": [
                98.29873,
                79.982834,
                135.28113
            ],
            "data": {
                "url": "https://api.artic.edu/api/v1/artworks/search?q=cats",
                "headers": [
                    {
                        "key": "",
                        "value": ""
                    }
                ]
            },
            "valueProperty": "_score",
            "searchEnabled": false,
            "useExactSearch": true,
            "key": "select",
            "type": "select",
            "selectValues": "data",
            "disableLimit": false,
            "limit": 25,
            "input": true
        },
        {
            "type": "button",
            "label": "Submit",
            "key": "submit",
            "disableOnInvalid": true,
            "input": true,
            "tableView": false
        }
    ]
lane-formio commented 4 months ago

So to clarify, are you expecting to see "undefined" instead of the "134.xxxxx"?

Also, are you able to reproduce this now? We have since updated the example builder.

Finally, looking at your form json it doesn't look like you are setting the data path to "data". You should also set the item template to display "labels" such as "{{ item.thumbnail.alt_text }}"

lane-formio commented 2 months ago
Agent Lane Doughtie linked Freshdesk ticket 45959 for this issue.