1

I created a new knob control widget on ThingsBoard using external JavaScript resources. External JavaScript resources are: https://code.jquery.com/jquery-1.9.0.js and https://cdnjs.cloudflare.com/ajax/libs/jQuery-Knob/1.2.13/jquery.knob.min.js

JavaScript:

self.onInit = function() {
    var $j=jQuery.noConflict();
    $j(".knob").knob();
}

HTML:

<div class=container>
    <input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66CC66" value="50">
</div>

The widget works well on its own. However, when added to the Dashboard, it causes errors to other existing widgets also on the same dashboard.

As seen from the image attached, the newKnobControl (which is the custom widget I created) is displayed and working. However, the existing built-in knob control widget on ThingsBoard can no longer display properly and there is also an error with displaying the TimeSeries bars. Timeseries Bars error stated as: Widget Error: TypeError: $.plot is not a function.

dashboard image

So, question is how can I add my custom widget to the same Dashboard as existing built-in widgets without causing errors to them?

ta.ng
  • 55
  • 1
  • 8
  • Your widget (or widget configuration/resources) is overriding the global `$`-handle (typically jquery) which is required for the widgets to work. – lupz Sep 08 '20 at 09:04
  • Tried using var $jq=jQuery.noConflict(); but still not working. – ta.ng Sep 09 '20 at 01:12
  • I created a little test widget using those external resources and a dashboard like yours. Everything seems to be working so far. I guess we will need to see the widgets code for further investigations. It might be possible to change the order of the widgets in your dashboard to find out which widget is overriding the `$`-handle. Also you could try to check the actual value of `$` with the developer tools of your browser. – lupz Sep 09 '20 at 07:09
  • I've edited the question to include the widget code. The TimeSeries Bars widget is able to work after adding in $.noConflict but the built-in knob control widget still does not display properly. – ta.ng Sep 09 '20 at 08:26

0 Answers0