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

Select component with data source URL - no error handling when URL not reachable or authorized

Open Rolf-MP opened this issue 1 year ago • 5 comments

Describe the bug I am using the select component with data source URL.

When the URL is not reachable, does not exist, or is not authorized, the select box remains empty with no error handling informing the user that something is wrong.

Version/Branch Multiple, including the default version currently on sandbox

Have not found a version where an error message was shown.

To Reproduce Steps to reproduce the behavior:

  1. As an example use HERE.com api, could be any other source I presume.
  2. Create an account, create app and api key.
  3. Replace <YOUR_HERE_API_KEY> in the form definition json below with your HERE api key.
{
  "display": "form",
  "components": [
    {
      "label": "Select",
      "widget": "choicesjs",
      "placeholder": "Type to search (1s delay in this demo)",
      "tableView": true,
      "dataSrc": "url",
      "data": {
        "url": "https://autocompletes.search.hereapi.com/v1/autocomplete",
        "headers": [
          {
            "key": "",
            "value": ""
          }
        ]
      },
      "valueProperty": "id",
      "template": "<span>{{ item.title }}</span>",
      "validate": {
        "select": false
      },
      "validateWhenHidden": false,
      "key": "select",
      "type": "select",
      "selectValues": "items",
      "disableLimit": false,
      "searchField": "q",
      "searchDebounce": 1,
      "filter": "apiKey=<YOUR_HERE_API_KEY>",
      "limit": 5,
      "noRefreshOnScroll": false,
      "input": true
    }
  ]
}
  1. Paste the above json in Form JSON on sandbox
  2. Start typing in the select box - it should be behaving nicely and provide options while you type.
  3. Corrupt the api key and/or url, start typing again.
  4. In the browser network traffic (dev tools) you'll see that the url is being queried but trows a 401.
  5. The select component will behave eerily silent - no error handling - no message to the user.

Expected behavior Show error in the component that the data source is not reachable.

It seems that there is a function handleLoadingError() in the select component that should put an error below the component but in my case at least it is not working.

Screenshots N/A

Additional context N/A

Rolf-MP avatar Aug 23 '24 10:08 Rolf-MP

It does display a high level error in the console: image

Rolf-MP avatar Aug 26 '24 16:08 Rolf-MP

It seems that there should be a componentError event emitted.

image

Is there a way this could be picked up to display an error? Preferably on the component itself but other wise the ability to issue an alert would already be a way to inform the user.

Rolf-MP avatar Aug 26 '24 16:08 Rolf-MP

I'll get this in front of planning to see if we would resource this, but it will likely end up as a lower priority item. But if anyone would like to submit a PR to address this I'd be more than happy to get it reviewed.

lane-formio avatar Oct 02 '24 14:10 lane-formio

My impression is that it is mostly done and that the lack of error display in the UI might have been an oversight at the time of implementation. I dug into it and would need hints to how to take it from what has been reported above.

Rolf-MP avatar Oct 02 '24 15:10 Rolf-MP

Ticket is created. For internal reference: FIO-9206.

VikkiAlenn avatar Oct 09 '24 13:10 VikkiAlenn