How to use widget's onError to display html

Issue #156 new
FrankJ created an issue

I wonder if it was possible to use a widget's onError function to change the content of the error container to sopmething different than an triangle with exclamation mark. I've tried

onError: function ($errorContainer, data, widgetId) {
    $('.error', $errorContainer).html(data.error);
  }

but it keeps on showing me just this triangle. Is this the right way to go or can I manage this on a different way?

Comments (2)

  1. Karuppasamy M

    You can display the error message instead of , by adding the below script in your widgets/WIDGET_NAME/WIDGET_NAME.js file.

    (function () {
      atlasboard.on("widgetError", function (e, data) {
        if (data.data.error) {
          data.$errorContainer.html('<span class="error">Error</span>');
        }
      });
    })();
    

    You can also do apply the same for all the widgets in your project by creating a new custom_error.js file under assets/javascript folder and invoke the same in your each dashboard/*.json file.

    "customJS": ["custom_error.js"]

  2. Mehdi Salem

    I have the same issue as described by @fjakob and it appears like the content is being overwritten before it could be displayed, when I use the onError callback. A simple workaround I've found is to use setTimeout with a delay of 0 (i. e., if will be executed immediately after the current event-queue has been processed) to replace the content of the error widget. Still, what is the use of having an onError event handler in the widget file if not for displaying some custom error notification. I haven't yet tried @mkaruppasamy's approach but it makes me wonder why we have to got to such lengths instead of just fixing the onError callback, which intuitively, seems like the right place to customize the shown error widget.

  3. Log in to comment